我正在做一个Jenkins作业,它将允许用户在我们的开发和生产环境中针对负载均衡器运行任务,并且需要对针对生产环境运行的作业进行“你确定吗?”检查。
我添加了一个简单而烦人的复选框,如下所示,但它总是表现为没有选中复选框。
pipeline {
parameters {
choice(
name: 'ANSIBLE_LB_ENV',
choices: ['---', 'dev', 'prod'],
description: 'Environment against which to run the LB config.'
)
booleanParam(
name: 'ANSIBLE_LB_SECRET_BUTTON',
defaultValue: false,
description: 'Secret Button.'
)
}
stages {
stage('sanityCheck') {
steps {
script {
echo "ANSIBLE_LB_ENV: ${ANSIBLE_LB_ENV}"
echo "ANSIBLE_LB_SECRET_BUTTON: ${ANSIBLE_LB_SECRET_BUTTON}"
if( ANSIBLE_LB_ENV == '---' ) {
currentBuild.result = 'ABORTED'
error("You must select a valid environment.")
}
if( ( ANSIBLE_LB_ENV == 'prod' ) && ( ANSIBLE_LB_SECRET_BUTTON != true ) ) {
currentBuild.result = 'ABORTED'
error("If you want to touch production you have to click the secret button.")
}
}
}
}
}
}
输出示例:
14:51:43 ANSIBLE_LB_ENV: prod
14:51:43 ANSIBLE_LB_SECRET_BUTTON: true
ERROR: If you want to touch production you have to click the secret button.
Finished: ABORTED
我做了
if( ( ANSIBLE_LB_ENV == 'prod' ) && ( ANSIBLE_LB_SECRET_BUTTON != true ) ) {...}
尽我所能明确定义,但它不允许我这样做
任何东西
当选择prod时。