我是詹金斯的新手。嘗試創建一個使用基于選擇的引數的基本管道。以下是我的腳本。
代碼 - -
pipeline{
agent {
label 'agent'
}
parameters {
choice choices: ['John', 'Stacy'], description: 'Choose one', name: 'Person'
}
stages {
stage('Print') {
steps {
echo "Hello ${params.Person}"
sh """if (${params.Person} = "John")
then
echo "Person is male."
else
echo "Person is female."
fi"""
}
}
}
}
現在無論我選擇什么選項,我的構建都成功完成。它總是顯示結果“人是女性。
以下是我的一個構建的結果。
Started by user ****
[Pipeline] Start of Pipeline
[Pipeline] node
Running on agent in
/home/temp/jenkins_agent/workspace/ChoiceBased PL
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Print)
[Pipeline] echo
Hello John
[Pipeline] sh
John = John
/home/temp/jenkins_agent/workspace/ChoiceBased PL@tmp/durable-
b7e98c46/script.sh: 1: John: not found
echo Person is female.
Person is female.
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
完成:成功
請建議我缺少什么?
uj5u.com熱心網友回復:
我會改變它只是為了在 Groovy 中而不是在 sh
stage('Print') {
steps {
echo "Hello ${params.Person}"
script {
if (params.Person == "John") {
echo "Person is male."
} else {
echo "Person is female."
}
}
}
}
然后當你選擇 Stacey 你會得到
[Pipeline] echo
Hello Stacy
[Pipeline] script
[Pipeline] {
[Pipeline] echo
Person is female.
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/410844.html
標籤:
下一篇:為每個異步API資料添加密鑰
