Jenkinsfile 不尊重选择正确分支的when 语句

问题描述 投票:0回答:1

我有一个 jenkins 文件阶段,仅当分支是

check-branch
分支时才应运行。

        stage('tf-apply') {
            when {
                    branch 'check-branch'
            }
            steps {
                dir('dr') {
                    input message: 'Do you want to apply this plan ? ', ok: 'Deploy'
                    sh 'terraform apply -input=false -auto-approve plan.out'
                }
            }
        }

git checkout 的 jenkins 管道输出是

Fetching changes from the remote Git repository
 > git rev-parse --resolve-git-dir /home/jenkins/workspace/tempp/.git # timeout=10
 > git config remote.origin.url https://github.airbus.corp/Airbus/gcp-blga-prj-dr.git # timeout=10
Fetching upstream changes from https:/serv/repo.git
 > git --version # timeout=10
 > git --version # 'git version 2.43.5'
using GIT_ASKPASS to set credentials 
 > git fetch --tags --force --progress -- https:/serv/repo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
Checking out Revision b92c212294863de300ddf5232ed635798999c71b (origin/check-branch)
Seen branch in repository origin/check-branch
Seen branch in repository origin/fix-branch
Seen branch in repository origin/main
Seen branch in repository origin/run-apply
Seen 4 remote branches
 > git show-ref --tags -d # timeout=10
Commit message: "Update Jenkinsfile"

该特定阶段的詹金斯管道输出是

[Pipeline] stage
[Pipeline] { (Print Branch Name)
[Pipeline] script
[Pipeline] {
[Pipeline] echo
Current branch is: origin/check-branch
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (tf-apply)
Stage "tf-apply" skipped due to when conditional
[Pipeline] getContext
[Pipeline] }
[Pipeline] // stage
[Pipeline] }

我也尝试过

        stage('tf-apply') {
            when {
                    branch 'origin/check-branch'
            }

但这也会被跳过。我在这里缺少什么?

jenkins jenkins-pipeline
1个回答
0
投票

您可能正在使用普通的管道作业,而不是多分支管道? 请参阅文档

请注意,这仅适用于多分支管道。

© www.soinside.com 2019 - 2024. All rights reserved.