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

前端 未结 12 748
闹比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:42

    You can strip the prefix from the variable pretty easily: ${GIT_BRANCH##origin/}

    Although this is not a very general solution, it's quite simple and I haven't seen a repository cloned by Jenkins, which would use something else than origin for the remote name.

    Update: Actually, ${GIT_BRANCH#*/} will work for any origin and even for branches containing slashes. The # does non-greedy glob matching, ## enables greedy matching. See Bash Reference Manual for details.

提交回复
热议问题