我正在尝试创建一个 Jenkins 管道,在第一阶段我在 sh shell 脚本中定义一个变量。然后我想根据先前定义的变量使用“何时”条件运行下一个阶段。
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: No such property: $BUILD for class: groovy.lang.Binding
我该怎么做?可能吗?谢谢!