Jenkins 2 如何使用 PowerShell 以及自定 build fail (指定 exit code)
Jenkins 除了用來做為 CI(持續性整合) 工具外,也可以與其他 plugin 配合達成其他目的(e.g.IIS restart、檔案壓縮備份…),今天就來看看可以怎麼與 PowerShell 整合執行 PowerShell 指令
文章大綱
- 安裝 PowerShell plugin
- 設定 Powershell plugin
- PowerShell 丟出 build fail
1. 安裝 PowerShell plugin
Manage Jenkins –> Manage Plugins

Available –> Filter

2. 設定 Powershell plugin
Build –> ADD BUILD STEP –> Windows PowerShell

Command
直接寫 Powershell 語法
大专栏 Jenkins 2 如何使用 PowerShell 以及自定 build fail (指定 exit code)sercontent.com/assets/3851540/22322570/e4af87d6-e3d7-11e6-9451-a82bd90e3358.png" alt="4commnad"/>
3. PowerShell 丟出 build fail
預設情況 Jenkins 只要有執行 PowerShell,不論是否正確執行皆會視為 SUCCESS,所以需要手動拋出 build fail
手動拋出錯誤(使用 try catch 為例)
- 將 PowerShell 實際執行的 command 用 try catch 包
catch 區段 丟出
exit 1以通知 Jenkins 拋出 build failTry
{
Get-Content C:securestringa.txt -ErrorAction Stop
}
Catch
{
write-output "get data fail!"
exit 1
}

參考資料
Jenkins 2 如何使用 PowerShell 以及自定 build fail (指定 exit code)的更多相关文章
- Jenkins入门之执行Powershell脚本
之前章节提到过powershell,如果需要构建复杂的任务时,使用cmd不是很方便(也可能是由于笔者不太熟悉cmd命令,这里见笑了),这时候powershell就派上用场了,这里并不详细介绍power ...
- jenkins slave启动报错:hudson.util.IOException2: Slave JVM has terminated. Exit code=126
添加mac slave节点报错如下:Expanded the channel window size to 4MB [11/07/14 19:11:54] [SSH] Starting slave p ...
- Jenkins执行批处理文件、powershell失败
今天搭建Jenkins持续集成环境,编译环境是.net core.整理了一些发布的命令配置在Jenkins,问题来了,使用powershell插件运行dotnet restore.dotnet bui ...
- Jenkins中使用Azure Powershell连接Service Fabric报错not recognized的原因与解决办法
一.使用背景 在涉及Azure service Fabric的自动化应用场景中,依赖于Service Fabric的Azure Powershell cmdlets,我们可以使用Jenkins能实现c ...
- 如何在jenkins的maven项目中,用mvn命令行指定findbugs的黑名单规则文件
一:问题背景 最近在研究jenkins的过程中,针对maven项目,打算添加findbugs进行静态检查,但我不太想在项目的pom中进行修改,最好可以只修改jenkins的job配置,即配置外部化. ...
- Jenkins - ERROR: Exception when publishing, exception message [Failure] Build step 'Send build artifacts over SSH' changed build result to UNSTABLE
今天在处理Jenkins的时候出现了一些异常,看着控制台,编译都是通过的,只是没有部署上来,查看了控制台日志,如下: 刚开始还以为是权限通道什么的,后来才发现是执行脚本根本不让执行,以前也遇到过,都是 ...
- jenkins将构建成功或失败的信息发送给指定URL(eg: pomelo采用jenkins持续集成)
先提供一个思路供大家参考,想将构建成功或者失败的信息发送给指定URL的话,可以这样:1.A构建后触发另一个构建B,构建B执行某个插件2.插件的功能: (1)利用jenkins API获取构建A最 ...
- [转] Jenkins pipeline 中获取 exit code, stdout and stderr 返回值和输出
[From] https://issues.jenkins-ci.org/browse/JENKINS-44930 其做法是,把stdout定向到一个文件,sh 配置 returnStatus: tr ...
- Azure PowerShell 在ARM环境下使用指定 vhd(本地化后的磁盘) 来创建虚拟机
#此脚本用于 Azure 存储账户中已有 vhd 镜像文件创建虚拟机,一般用于做好镜像测试 #----------------------------------------------------- ...
随机推荐
- 《C++语言导学》小记
我看的这本是Bjarne Stroustrup写的,南开大学的杨巨峰和王刚译的.这本书不适合初学者看,我就是大概翻了翻其中感兴趣的章节. 这本书第14章的标题是“历史和兼容性”,这节内容我看了收获很深 ...
- codeforces 596
C 题意 定义p-binary为2^x+p 现在给你一个数x,和一个p. 问你最少用多少个p-binary能构造出x,如果没有输出-1 题解 转化为: x = 2^x1 + 2^x2 + ... + ...
- C# 基础Array
一.Array的作用 连续定义多个相同类型的变量,比如我定义1000个学生的学生年龄,int[] age = new int[1000];不需要慢慢的一个一个变量的定义,数组是不是很方便. 需要注意的 ...
- gff文件提取cds
#!/usr/bin/perl use strict; use warnings; ########input######## ];my $cut = &cut($gff);my %cut = ...
- Spring的设计理念和整体架构
1.Spring的各个子项目 Spring Framework(Core):这是我们熟知的Spring项目的核心.Spring Framework(Core)中包含了一系列Ioc容器的设计,提供了依赖 ...
- 洛谷 P3808 【模板】AC自动机(简单版)
传送门:https://www.luogu.org/problem/P3808 题解:是一个AC自动机的裸题了,注释加在代码里面了 #include<bits/stdc++.h> usin ...
- 多标签图像分类任务的评价方法-mAP
http://blog.sina.com.cn/s/blog_9db078090102whzw.html 多标签图像分类(Multi-label Image Classification)任务中图片的 ...
- 线段树、最短路径、最小生成树、并查集、二分图匹配、最近公共祖先--C++模板
线段树(区间修改,区间和): #include <cstdio> #include <iostream> #include <cstring> using name ...
- [Algo] 253. Longest Substring Without Repeating Characters
Given a string, find the longest substring without any repeating characters and return the length of ...
- British postal system to launch parcel postboxes
1 单词 parcel n. 包裹 pilot n. 试行计划 2 句子 1400 of the new boxes will be installed at 30 locations across ...
