【发布时间】:2021-02-04 02:30:18
【问题描述】:
stage('Preparation') {
steps {
script{
if(Deployment == 'UAT'){
goals = 'mvn clean install -Denvironment=uat '
script_arg='''shutdown.sh uat | sleep 20 | startup.sh uat'''
}
else{
goals = 'mvn clean install -Denvironment=dev'
script_arg='''shutdown.sh dev | sleep 20 | startup.sh dev'''
}
}
}
}
stage('Build') {
steps{
sh goals
}
}
stage('Deploy') {
steps([$class: 'BapSshPromotionPublisherPlugin']) {
sshPublisher(
continueOnError: false, failOnError: true,
publishers: [
sshPublisherDesc(
configName: "ABC",
verbose: true,
transfers: [
sshTransfer(sourceFiles: "target/abcd.war",
removePrefix: "/target",
remoteDirectory: "/remote",
execCommand: '''shutdown.sh uat | sleep 20 | startup.sh uat''')
]
)
]
)
}
}
我是詹金斯的新手。我正在尝试设置管道。 我上面的代码工作正常,但我想根据环境 dev/uat 传递执行命令 我在准备阶段创建了变量 script_arg 并希望在部署阶段用作 execCommand
部署 --> 步骤 --> sshPublisher --> 发布者 --> sshPublisherDesc --> 传输
但是当我如下替换它时
execCommand: "${script_arg}"
这不起作用。
【问题讨论】:
-
你在哪里添加了这个 execCommand?
-
部署 --> 步骤 --> sshPublisher --> 发布者 --> sshPublisherDesc --> 转移
-
我正在用代码'${script_arg}'替换上面的execCommand
标签: jenkins jenkins-pipeline jenkins-plugins jenkins-groovy