下面是Jenkins pipeline。它针对salt master服务器上存储在.txt文件中的奴才列表运行一个状态。下面的命令在salt master cli上运行良好:
salt --list `awk -vORS=, '{ print $1 }' /srv/salt/TMjenkins/minions.txt | sed 's/,$/\n/'` test.ping
但是,当我通过Jenkins管道运行它时,我在美元符号后得到非法的字符串主体字符。salt master在远程服务器中,因此我无法在本地执行cmd。到目前为止,我尝试在“””“"”和“"”'''中传递cmd,也是{ print "${1}\”}。到目前为止没有任何效果。如有任何建议,不胜感激。
pipeline = {
ansiColor('xterm') {
def remote = [:]
remote.name = 'saltmaster'
remote.host = 'xx.xxx.xx.x'
remote.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: 'saltmaster', passwordVariable: 'password', usernameVariable: 'ops')]) {
remote.user = 'xxx'
remote.password = password
stage('Filetransfer') {
sshCommand remote: remote, command: " salt -L `awk -vORS=, '{ print \"${1}\" }' /srv/salt/TMjenkins/minions.txt | sed 's/,$/\n/'` test.ping "
}
}
sh '/home/jenkins/jenkins-data/slack_notification.sh " ${minionid}" "Deployment finished successfully" "good" ":jenkins:"'
}
}
postFailure = {
sh '/home/jenkins/jenkins-data/slack_notification.sh " ${minionid}" "Unfortunately deployment was unsuccessful this time" "danger" ":jenkinserror:"'
}
postAlways = {
echo 'Cleaning Workspace now'
env.WORKSPACE = pwd()
sh "rm ${env.WORKSPACE}/* -fr"
}
node{
properties([
parameters([
string(name: 'Region', defaultValue: '', description: 'Region for which the process should run. ')
])
])
try {
pipeline()
} catch (e) {
postFailure()
throw e
} finally {
postAlways()
}
}
1条答案
按热度按时间toe950271#
如果你想跳过它,你需要避开你的
$
符号。变成
以及
变成
最后,不要使用bash脚本发送Slack通知,而应该使用Slack plugin for Jenkins,如下所示:
See also