How to receive local Git branch name with Jenkins Git plugin?

前端 未结 12 749
闹比i
闹比i 2020-12-12 17:52

I am using Branch Specifier option of Jenkins Git plugin (v2.0) to run build on specific branch, e.g. 1.4.

${GIT_BRANCH} in this case conta

12条回答
  •  时光取名叫无心
    2020-12-12 18:35

    I ran into the problem today. The reason is Jenkins git plug-in will add "origin/" to any branch name you supplied to GIT_BRANCH build parameter. See https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin

    The git plugin sets several environment variables you can use in your scripts: GIT_BRANCH - Name of the branch currently being used, e.g. "master" or "origin/foo"

    As a result, when you build with parameter GIT_BRANCH = foo, Jenkins will just add "origin/" in front of it. Then, when you do

    git check out ${GIT_BRANCH}
    

    you are actually doing

    git check out origin/foo
    

    What you can do to avoid this, is using something else in your build parameter, such as GIT_BRANCH_NAME or what ever else, just do not use GIT_BRANCH. In configuration, delete the GIT_BRANCH parameter, and add another one with name GIT_BRANCH_NAME. Then in "Build with parameter", under GIT_BRANCH_NAME, specify your branch.

提交回复
热议问题