在Jenkins的Console Output中有时会看到‘+’开头的shell命令调试信息,看起来比较混乱。原因是Jenkins默认用‘-xe’的选项去运行‘sh’命令。例如如下pipeline会产生后续的输出。
pipeline {
agent none
stages {
stage('Example') {
steps {
node('master') {
sh 'dmesg | grep raspberrypi | grep soc'
}
}
}
}
}
输出:
[Pipeline] sh
+ dmesg
+ grep raspberrypi
+ grep soc
解决方法是自定义一个运行shell脚本的函数,并在每个命令行前加入‘#!/bin/sh -e\n’选项。
def mysh(cmd, returnStatus) {
return sh (script: '#!/bin/sh -e\n'+ cmd, returnStatus: returnStatus)
}
pipeline {
agent none
stages {
stage('Example') {
steps {
node('master') {
mysh ('dmesg | grep raspberrypi | grep soc', true)
}
}
}
}
}