我正在從事一項 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
I've made if( ( ANSIBLE_LB_ENV == 'prod' ) && ( ANSIBLE_LB_SECRET_BUTTON != true ) ) {...}as explicitly-defined as I can, but it just won't let me do anything when prod is selected.
uj5u.com熱心網友回復:
ANSIBLE_LB_SECRET_BUTTON回傳為 a String,而不是 a Boolean:)
如此簡單,
if( ( ANSIBLE_LB_ENV == 'prod' ) && ( ANSIBLE_LB_SECRET_BUTTON != "true" ) ) {...}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/510162.html
標籤:詹金斯詹金斯管道
