Jenkinsfile 中的条件步骤
Conditional step in Jenkinsfile
我有以下情况:
.
.
.
stage('My stage')
{
steps
{
sh 'my_command1.sh'
sh 'my_command2.sh'
sh 'my_command3.sh'
}
}
.
.
.
例如,只有在特定条件下才能执行步骤“my_command2.sh”吗?我知道可以用“when”标记定义条件语句,但条件对所有阶段都有影响。我只想将此行为限制为一步。
谢谢。
您可以使用 script
那么你的舞台会是这样的:
stage('My Stage') {
steps {
script{
sh 'my_command1.sh'
if(condition){
sh 'my_command2.sh'
}
sh 'my_command3.sh'
}
}
}
您还可以从 official documentation
检查声明步骤
我有以下情况:
.
.
.
stage('My stage')
{
steps
{
sh 'my_command1.sh'
sh 'my_command2.sh'
sh 'my_command3.sh'
}
}
.
.
.
例如,只有在特定条件下才能执行步骤“my_command2.sh”吗?我知道可以用“when”标记定义条件语句,但条件对所有阶段都有影响。我只想将此行为限制为一步。
谢谢。
您可以使用 script
那么你的舞台会是这样的:
stage('My Stage') {
steps {
script{
sh 'my_command1.sh'
if(condition){
sh 'my_command2.sh'
}
sh 'my_command3.sh'
}
}
}
您还可以从 official documentation
检查声明步骤