有人可以帮我将下面的 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 branch 并根据 git branch 动态设置 jenkins build id
最佳答案
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}"
}
}
}
}
}
}
关于jenkins - 如何将 jenkins 脚本化管道转换为声明性管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53329761/