我想将新的Jenkinsfile用于新工作。
我在单独的存储库中有jenkinsfile:
script { env.BRANCHDEPLOY = input message: 'User input required', ok: 'Deploy!', parameters: [choice(name: 'Branch to deploy', choices: '${branch1}\n${branch2}\n${branch3}', description: 'What branch you wont deploy?')] } echo "${env.BRANCHDEPLOY}"
${env.BRANCHDEPLOY}
问题是我无法在用户选择的变量中使用它。
我只需要让用户从另一个gitlab存储库中选择要部署的分支即可。
您只是犯了一个错误,那就是在必须用脚本替换的变量周围加上单引号,因此只需将单引号更改为双引号即可。
"${branch1}\n${branch2}\n${branch3}"
示例:第二阶段打印所选选项
pipeline { agent any environment{ branch1 = 'stack' branch2 = 'over' branch3 = 'flow' } stages { stage('Stage-One') { steps { script { env.BRANCHDEPLOY = input message: 'User input required', ok: 'Deploy!', parameters: [choice(name: 'Branch to deploy', choices: "${branch1}\n${branch2}\n${branch3}", description: 'What branch you wont deploy?')] } } } stage('Stage-Two'){ steps{ sh "echo ${BRANCHDEPLOY}" } } } }