要解决Bitbucket Branch Source插件在检出标签时未设置TAG_NAME变量的问题,可以使用以下方法:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
script {
checkout([$class: 'GitSCM',
branches: [[name: '*/tags/*']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CloneOption', noTags: false, reference: '', shallow: false]],
submoduleCfg: [],
userRemoteConfigs: [[url: 'https://bitbucket.example.com/repo.git']]])
env.TAG_NAME = env.BRANCH_NAME // 设置TAG_NAME变量为当前分支名
}
}
}
stage('Build') {
steps {
echo "Building tag ${env.TAG_NAME}"
// 在这里执行构建操作
}
}
// 其他阶段...
}
}
node {
stage('Checkout') {
checkout([$class: 'GitSCM',
branches: [[name: '*/tags/*']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CloneOption', noTags: false, reference: '', shallow: false]],
submoduleCfg: [],
userRemoteConfigs: [[url: 'https://bitbucket.example.com/repo.git']]])
env.TAG_NAME = env.BRANCH_NAME // 设置TAG_NAME变量为当前分支名
}
stage('Build') {
echo "Building tag ${env.TAG_NAME}"
// 在这里执行构建操作
}
// 其他阶段...
}
以上代码示例中,我们在检出代码后设置了TAG_NAME变量为当前分支名。这样,在后续的构建阶段中,可以使用该变量来引用标签名。