Jenkins管道-Jenkins SCM步骤。检出返回无效数据,不参考所提供的参数

时间:2019-07-17 08:19:21

标签: jenkins jenkins-pipeline jenkins-plugins

我正在为我的项目设置CI / CD,并决定使用Jenkins Pipeline。我基本上需要什么:

  1. 从所选分支构建(从下拉列表中选择)
  2. 有条件地执行某些阶段(取决于分支)

我将管道配置为从scm提取Jenkinsfile: enter image description here 然后,我决定编写如下的cutom scm checkout:

stage('Checkout specific branch') {
        steps {
            echo "Checking out ${params.branchToBuild}..."
            script {
                def actualBranchCheckout = checkout([$class: 'GitSCM',
                                        branches: [
                                                [name: "${params.branchToBuild}"]
                                        ],
                                        doGenerateSubmoduleConfigurations: false,
                                        extensions: [[$class: 'LocalBranch', localBranch: "**"]],
                                        submoduleCfg: [],
                                        userRemoteConfigs: [
                                                [credentialsId: "${env.REPO_SSH_CREDS_ID}", url: "${env.REPO_SSH_URL}"]
                                        ]
                ])
            }
        }
    }

我有很多担忧。签出Jenkinsfile的分支时会设置GIT_环境变量。

GIT_BRANCH=origin/master
GIT_COMMIT=11a5800b6ca31bc81545fa4874d73fa275c820c2, GIT_LOCAL_BRANCH=master, GIT_PREVIOUS_COMMIT=11a5800b6ca31bc81545fa4874d73fa275c820c2

那很好,但是当我执行结帐时,不会使用实际值进行更新,并且保持不变。 好的,该方法本身返回的map可能包含我需要的内容,因此我可以手动重置它们,对吧? 但是,结帐开发分支时它们却是相同的:

以下是日志:

Obtained Jenkinsfile from git git@bitbucket.org:team/repo.git
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/Repo/repo_pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
using credential jenkins-bitbucket
Cloning the remote Git repository
Cloning repository git@bitbucket.org:team/repo.git
 > git init /var/lib/jenkins/workspace/Repo/repo_pipeline # timeout=10
Fetching upstream changes from git@bitbucket.org:team/repo.git
 > git --version # timeout=10
using GIT_SSH to set credentials 
 > git fetch --tags --progress git@bitbucket.org:team/repo.git +refs/heads/*:refs/remotes/origin/*
 > git config remote.origin.url git@bitbucket.org:team/repo.git # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url git@bitbucket.org:team/repo.git # timeout=10
Fetching upstream changes from git@bitbucket.org:team/repo.git
using GIT_SSH to set credentials 
 > git fetch --tags --progress git@bitbucket.org:team/repo.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 31e727bf81b3379c9aa80224b8f941bc867acd77 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 31e727bf81b3379c9aa80224b8f941bc867acd77
Commit message: "print out variables"
 > git rev-list --no-walk 11a5800b6ca31bc81545fa4874d73fa275c820c2 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout specific branch)
[Pipeline] echo
Checking out develop...
[Pipeline] script
[Pipeline] {
[Pipeline] checkout
using credential jenkins-bitbucket
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url git@bitbucket.org:team/repo.git # timeout=10
Fetching upstream changes from git@bitbucket.org:team/repo.git
 > git --version # timeout=10
using GIT_SSH to set credentials 
 > git fetch --tags --progress git@bitbucket.org:team/repo.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse origin/develop^{commit} # timeout=10
Checking out Revision 11a5800b6ca31bc81545fa4874d73fa275c820c2 (origin/develop)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 11a5800b6ca31bc81545fa4874d73fa275c820c2
 > git branch -a -v --no-abbrev # timeout=10
 > git checkout -b develop 11a5800b6ca31bc81545fa4874d73fa275c820c2
Commit message: "another try"
First time build. Skipping changelog.
[Pipeline] echo
[GIT_BRANCH:origin/master, GIT_COMMIT:31e727bf81b3379c9aa80224b8f941bc867acd77, GIT_LOCAL_BRANCH:master, GIT_PREVIOUS_COMMIT:11a5800b6ca31bc81545fa4874d73fa275c820c2, GIT_PREVIOUS_SUCCESSFUL_COMMIT:11a5800b6ca31bc81545fa4874d73fa275c820c2, GIT_URL:git@bitbucket.org:team/repo.git]

我还有另一个选项可以手动完成所有操作,例如git rev-parse --abbrev-ref HEAD用于分支等。有人知道如何解决这个问题/这是已知问题还是我做错了什么方法?

0 个答案:

没有答案