有人可以帮助我将下面的Jenkins脚本化管道转换为声明性管道
node('agent') {
if ( ! "${GIT_BRANCH}".isEmpty()) {
branch="${GIT_BRANCH}"
} else {
echo 'The git branch is not provided, exiting..'
sh 'exit 1'
}
version = extract_version("${GIT_BRANCH}")
if ( "${GIT_BRANCH}".contains("feature")) {
currentBuild.displayName = "${version}-SNAPSHOT-${env.BUILD_ID}"
}
else {
currentBuild.displayName = "${version}-${env.BUILD_ID}"
}
}
我正在尝试检查是否提供了git分支,并根据git分支动态设置了jenkins构建ID
答案 0 :(得分:3)
pipeline {
agent {
label 'agent'
}
stages{
stage('stag1'){
steps {
script {
if ( ! "${GIT_BRANCH}".isEmpty()) {
branch="${GIT_BRANCH}"
} else {
echo 'The git branch is not provided, exiting..'
sh 'exit 1'
}
version = extract_version("${GIT_BRANCH}")
if ( "${GIT_BRANCH}".contains("feature")) {
currentBuild.displayName = "${version}-SNAPSHOT-${env.BUILD_ID}"
}
else {
currentBuild.displayName = "${version}-${env.BUILD_ID}"
}
}
}
}
}
}