【发布时间】:2020-05-20 06:28:32
【问题描述】:
下面是 Jenkins 流水线。它针对存储在 salt 主服务器上的 .txt 文件中的 minions 列表运行状态。以下命令在 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()
}
}
【问题讨论】:
-
你需要转义
$。
标签: jenkins jenkins-pipeline salt-stack salt