在運行以下代碼時,我將進入else字串比較部分。
但無法進入else布爾比較部分的塊。
pipeline {
agent any
parameters{
string(
name: "s_Project_Branch_Name", defaultValue: "master",
description: "Enter Brnach Name")
}
stages {
stage('Example') {
input {
message "Proceed to Prod Deployment with ${params.s_Project_Branch_Name} branch?"
ok "Yes"
parameters {
string(name: 'PERSON', defaultValue: 'master', description: 'Who should I say hello to?')
booleanParam(name: "TOGGLE", defaultValue: false, description: "Check this box to Proceed.")
}
}
steps {
// echo "Hello, ${PERSON}, nice to meet you."
script{
echo 'String'
if ("${PERSON}" == "${params.s_Project_Branch_Name}") {
echo 'I only execute on the master branch'
} else {
echo 'I execute elsewhere'
currentBuild.result = "FAILURE"
}
}
script{
echo 'Boolean'
echo "${TOGGLE}"
if ("${TOGGLE}") {
echo 'I only execute if boolean true'
} else {
error('I only execute if boolean false')
currentBuild.result = "FAILURE"
}
}
}
}
}
}
uj5u.com熱心網友回復:
當您進行字串插值時"${TOGGLE}",您將得到一個字串,而不是布林值。如果您想獲得布林值,您可以通過執行直接訪問變數params.TOGGLE。所以像下面這樣改變條件。
if (params.TOGGLE) {
echo 'I only execute if boolean true'
} else {
error('I only execute if boolean false')
currentBuild.result = "FAILURE"
}
或者
if ("${TOGGLE}" == "true") {
echo 'I only execute if boolean true'
} else {
error('I only execute if boolean false')
currentBuild.result = "FAILURE"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/526269.html
下一篇:Pandas迭代地從字典中添加值
