gpt4 book ai didi

jenkins - 如何将 jenkins 脚本化管道转换为声明性管道

转载 作者:行者123 更新时间:2023-12-04 18:22:58 24 4
gpt4 key购买 nike

有人可以帮我将下面的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com