Jenkins Git branch variable is not replaced with value correctly

I’m currently having troubles with a build on Jenkins, more specifically with the Git plugin in combination with a parameter, but only on a specific job.

I’m having a Jenkins job that builds a release version of our software. The software is inside Git on a branch named ‘release/’ (for example release/06.03). Because multiple versions are possible I have a properties file where the possible release git branches are defined and I use Extented Choice Parameter to make single select dropdown box

enter image description here

The user selects one of the release_branch options and enters the patch version number and then the job can be build. This exact same setup works correctly for other release jobs we have where I use the exact same setup and the same properties file. Except for just one job.

The first step in the process (for debugging purposes) is a Windows batch command where I echo the %release_branch% variable.

enter image description here

Then I checkout the code from Git using the $release_branch variable (I’ve removed sensitive information from the screenshot below, the correct repository and credentials are filled in)

enter image description here

After the repository is checked out a groovy script starts where other parameters are determined based on the software that was checked out.

Now when I execute this job and check the loggings some strange stuff is happening (I have again replaced some sensitive information:

  • Customer name has been replaced with <customer >
  • The proxy URL has been replaced with <proxy ip and port >
  • The git URL has been replaced with <git repository url >.git

The sensitive information has been confirmed and definitely works):


The following Jenkins loggings are from the jobs that goes wrong

Started by user Rick Veenstra
[EnvInject] - Loading node environment variables.
Building in workspace D:/Jenkins/builds/git/repositories\<customer>
Running Prebuild steps
[<customer>] $ cmd /c call C:\Windows\TEMP\hudson48240663439325326.bat

D:\Jenkins\builds\git\repositories\<customer>>echo Will checkout from Git using branch: release/06.03 
Will checkout from Git using branch: release/06.03

D:\Jenkins\builds\git\repositories\<customer>>exit 0 
Success build forhudson.tasks.BatchFile@f3d5a79
Wiping out workspace first.
Cloning the remote Git repository
Cloning repository <git repository url>.git
 > D:\Program Files (x86)\Git\bin\git.exe init D:\Jenkins\builds\git\repositories\<customer> # timeout=10
Fetching upstream changes from <git repository url>.git
 > D:\Program Files (x86)\Git\bin\git.exe --version # timeout=10
using .gitcredentials to set credentials
 > D:\Program Files (x86)\Git\bin\git.exe config --local credential.helper store --file=\"C:\Windows\TEMP\git1134080240648513421.credentials\" # timeout=10
Setting http proxy: <proxy ip and port>
 > D:\Program Files (x86)\Git\bin\git.exe -c core.askpass=true fetch --tags --progress <git repository url>.git +refs/heads/*:refs/remotes/refs/heads/release/06.03/*
 > D:\Program Files (x86)\Git\bin\git.exe config --local --remove-section credential # timeout=10
 > D:\Program Files (x86)\Git\bin\git.exe config remote.refs/heads/release/06.03.url <git repository url>.git # timeout=10
 > D:\Program Files (x86)\Git\bin\git.exe config remote.refs/heads/release/06.03.fetch +refs/heads/*:refs/remotes/refs/heads/release/06.03/* # timeout=10
 > D:\Program Files (x86)\Git\bin\git.exe config remote.refs/heads/release/06.03.url <git repository url>.git # timeout=10
Fetching upstream changes from <git repository url>.git
using .gitcredentials to set credentials
 > D:\Program Files (x86)\Git\bin\git.exe config --local credential.helper store --file=\"C:\Windows\TEMP\git993807724023012035.credentials\" # timeout=10
Setting http proxy: <proxy ip and port>
 > D:\Program Files (x86)\Git\bin\git.exe -c core.askpass=true fetch --tags --progress <git repository url>.git +refs/heads/*:refs/remotes/refs/heads/release/06.03/*
 > D:\Program Files (x86)\Git\bin\git.exe config --local --remove-section credential # timeout=10
 > D:\Program Files (x86)\Git\bin\git.exe rev-parse "refs/remotes/refs/heads/$release_branch/release/06.03^{commit}" # timeout=10
 > D:\Program Files (x86)\Git\bin\git.exe rev-parse "refs/remotes/refs/heads/$release_branch/refs/heads/release/06.03^{commit}" # timeout=10
Checking out Revision 64e002379c30c545cbf05e6c062df2a78990cb1e (refs/remotes/refs/heads/$release_branch/release/06.03)
 > D:\Program Files (x86)\Git\bin\git.exe config core.sparsecheckout # timeout=10
 > D:\Program Files (x86)\Git\bin\git.exe checkout -f 64e002379c30c545cbf05e6c062df2a78990cb1e
 > D:\Program Files (x86)\Git\bin\git.exe rev-list 64e002379c30c545cbf05e6c062df2a78990cb1e # timeout=10
Notified Stash for commit with id 64e002379c30c545cbf05e6c062df2a78990cb1e
==============================
[-- STARTING GROOVY SCRIPT --]
==============================
Based on the git branch and client the Jenkins parameters will be determined and set.
-- Branch: refs/heads/release/06.03/release/06.03

As you can see the Windows Batch prints the %release_branch% parameter as “release/06.03” as is correct. But then the parameter is used in the Git plugin and things get messed up. First everything seems fine but then the parameter name $release_branch is printed with right behind it the replaced value.

D:\Program Files (x86)\Git\bin\git.exe rev-parse "refs/remotes/refs/heads/$release_branch/release/06.03^{commit}" #timeout=10
D:\Program Files (x86)\Git\bin\git.exe rev-parse "refs/remotes/refs/heads/$release_branch/refs/heads/release/06.03^{commit}"
# timeout=10 Checking out Revision 64e002379c30c545cbf05e6c062df2a78990cb1e
(refs/remotes/refs/heads/$release_branch/release/06.03)

And then in the groovy script the first $release_branch is replaced with the value again and thus it shows release/06.03 twice

-- Branch: refs/heads/release/06.03/release/06.03

I’m at a loss as to why the parameter is not replacing properly and why it I don’t see the term ‘origin’ as I see with other loggings, since I only have one remote git server defined I expect something like below


The following Jenkins loggings are from one of the other jobs that work correctly

[EnvInject] - Loading node environment variables.
Building in workspace D:/Jenkins/builds/git/repositories/<customer 2>
Wiping out workspace first.
Cloning the remote Git repository
Cloning repository <git repository url 2>.git
 > D:\Program Files (x86)\Git\bin\git.exe init D:\Jenkins\builds\git\repositories\<customer 2># timeout=10
Fetching upstream changes from <git repository url 2>.git
 > D:\Program Files (x86)\Git\bin\git.exe --version # timeout=10
using .gitcredentials to set credentials
 > D:\Program Files (x86)\Git\bin\git.exe config --local credential.helper store --file=\"C:\Windows\TEMP\git6918391337668560662.credentials\" # timeout=10
Setting http proxy: 10.30.60.218:8080
 > D:\Program Files (x86)\Git\bin\git.exe fetch --tags --progress <git repository url 2>.git +refs/heads/*:refs/remotes/origin/*
 > D:\Program Files (x86)\Git\bin\git.exe config --local --remove-section credential # timeout=10
 > D:\Program Files (x86)\Git\bin\git.exe config remote.origin.url <git repository url 2>.git # timeout=10
 > D:\Program Files (x86)\Git\bin\git.exe config remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > D:\Program Files (x86)\Git\bin\git.exe config remote.origin.url <git repository url 2>.git # timeout=10
Fetching upstream changes from <git repository url 2>.git
using .gitcredentials to set credentials
 > D:\Program Files (x86)\Git\bin\git.exe config --local credential.helper store --file=\"C:\Windows\TEMP\git6568474183277604659.credentials\" # timeout=10
Setting http proxy: 10.30.60.218:8080
 > D:\Program Files (x86)\Git\bin\git.exe fetch --tags --progress <git repository url 2>.git +refs/heads/*:refs/remotes/origin/*
 > D:\Program Files (x86)\Git\bin\git.exe config --local --remove-section credential # timeout=10
 > D:\Program Files (x86)\Git\bin\git.exe rev-parse "refs/remotes/origin/release/06.03^{commit}" # timeout=10
 > D:\Program Files (x86)\Git\bin\git.exe rev-parse "refs/remotes/origin/refs/heads/release/06.03^{commit}" # timeout=10
Checking out Revision ed0da50edd4e55e8ea1f5fc3c711d191ad217534 (refs/remotes/origin/release/06.03)
 > D:\Program Files (x86)\Git\bin\git.exe config core.sparsecheckout # timeout=10
 > D:\Program Files (x86)\Git\bin\git.exe checkout -f ed0da50edd4e55e8ea1f5fc3c711d191ad217534
 > D:\Program Files (x86)\Git\bin\git.exe rev-list 6d3be94009a76663e3efec2daa72dff2754ccab6 # timeout=10
Notified Stash for commit with id ed0da50edd4e55e8ea1f5fc3c711d191ad217534
==============================
[-- STARTING GROOVY SCRIPT --]
==============================
Based on the git branch and client the Jenkins parameters will be determined and set.
-- Branch: origin/release/06.03

Does anybody know what is going wrong exactly and how to fix the problem?

Kind regards,
Rick

I’m running the following (latest) versions:

  • Jenkins: 1.597
  • Git plugin: 2.3.4
  • Git Parameter plugin: 0.4.0′
  • Extended Choice Parameter Plugin: 0.34

Git Baby is a git and github fan, let's start git clone.