Jenkins 詹金斯管道公司“;什么时候;具有sh定义变量的条件
我正在尝试创建一个Jenkins管道,在第一个阶段中,我在sh shell脚本中定义了一个变量。 然后,我想根据前面定义的变量,使用“when”条件运行下一个阶段Jenkins 詹金斯管道公司“;什么时候;具有sh定义变量的条件,jenkins,jenkins-pipeline,jenkins-declarative-pipeline,Jenkins,Jenkins Pipeline,Jenkins Declarative Pipeline,我正在尝试创建一个Jenkins管道,在第一个阶段中,我在sh shell脚本中定义了一个变量。 然后,我想根据前面定义的变量,使用“when”条件运行下一个阶段 pipeline { agent { label 'php71' } stages { stage('Prepare CI...') { steps{ sh ''' # Get the comment tha
pipeline {
agent { label 'php71' }
stages {
stage('Prepare CI...') {
steps{
sh '''
# Get the comment that was made on the PR
COMMENT=`echo $payload | jq .comment.body | tr -d '"'`
if [ "$COMMENT" = ":repeat: Jenkins" ]; then
BUILD="build"
fi
'''
}
}
stage('Build Pre Envrionment') {
agent { label 'php71' }
when {
expression { return $BUILD == "build" }
}
steps('Build') {
sh '''
echo $BUILD
echo $COMMENT
'''
}
}
}
}
这给了我一个错误:
groovy.lang.MissingPropertyException:没有这样的属性:$buildforclass:groovy.lang.Binding
我怎么做?可能吗?
谢谢大家! 可能使用Jenkins脚本化管道,它比声明性管道更灵活。
打印sh脚本中的值,并使用returnStdout使其可用于管道脚本。有关更多详细信息,请参阅。我在这里找到了一些方法:我只是想找到一个更好的解决方案,而不必使用文件。。。