Jenkins + Git Publisher - How to get back to {GIT_BRANCH}?

I am using the current version of the Git plugin (provider and publisher of SCM) on Jenkins 1.500. The SCM poll works fine using my Git HTTP URL and the build branch settings for the feature- * feature. This picks up changes in any branch, for example, "feature-1234", runs build / testing / coverage tasks and reports on success or failure. All of this works great, including merging with the integration branch, where the code should exit after successfully building and validating the code.

The problem is trying to bring the completed BACK assembly branch to the beginning, to the same branch "feature-1234". In this case, the assembly variable "GIT_BRANCH" contains "origin / feature-1234", which causes the following error and failure in Git Publisher after a successful build:

Pushing HEAD to branch origin/feature-1234 at repo origin ERROR: Failed to push branch origin/feature-1234 to origin hudson.plugins.git.GitException: Command "/usr/bin/git push https://jenkins:jenkinsPWD@myproject.com/git/project HEAD:origin/feature-1234" returned status code 1: stdout: stderr: error: unable to push to unqualified destination: origin/feature-1234 The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref. error: failed to push some refs to 'https://jenkins:jenkinsPWD@myproject.com/git/project' at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:897) at hudson.plugins.git.GitAPI.launchCommand(GitAPI.java:858) at hudson.plugins.git.GitAPI.push(GitAPI.java:915) at hudson.plugins.git.GitPublisher$4.invoke(GitPublisher.java:351) at hudson.plugins.git.GitPublisher$4.invoke(GitPublisher.java:333) at hudson.FilePath.act(FilePath.java:865) at hudson.FilePath.act(FilePath.java:838) at hudson.plugins.git.GitPublisher.perform(GitPublisher.java:333) at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:810) at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:785) at hudson.model.Build$BuildExecution.post2(Build.java:183) at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:732) at hudson.model.Run.execute(Run.java:1582) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:236) Build step 'Git Publisher' changed build result to FAILURE Build step 'Git Publisher' marked build as failure 

Look at the extra “background” there? origin / feature-1234 <== that the current value is $ {GIT_BRANCH}, and although I understand that this is a remote branch and that’s it, it prevents me from starting the process that we want to execute.

If I am missing something simple, I would like to hear it. But I tried many different settings for the various git related parts of my assembly, and nothing seems to allow me to pass the merged and verified code back to the working branch (unlike the integration branch, which is easy to do.

+8
git jenkins
source share
4 answers

The workaround for me seems to push the branch manually, at least when it will be the same every time.

+1
source share

In the configuration configuration of the source control => advance there is a field "Name", you need to specify the repository identifier, and then use it in the git publisher plugin: "Target remote name"

These two names should be the same look at the "?" - get more information

+1
source share

I push changes manually. You can use the Windows environment variable as shown below in batch scripts:

This is evaluated, for example. 'git check function -1234'

 git checkout %GIT_BRANCH:origin/= % 

This is evaluated, for example. 'git origin button -1234'

 git push %GIT_BRANCH:/= % 

You can also do something similar with ${GIT_BRANCH##origin/} tokens such as ${GIT_BRANCH##origin/} and ${GIT_BRANCH#*/} . They work in some Jenkins plugins, but not all, so it may not work in Git Publisher.

+1
source share

I recommend /refs/remotes/origin/feature-1234 up full-featured /refs/remotes/origin/feature-1234 as your build branch of Git. Thus, it seems to me more understandable.

In this case, your $ GIT_BRANCH will be magically set by Jenkins to origin/feature-1234 in the same way as you observed.

Then, instead of using too complex (but portable) GitPublisher, simply add a step after building the "Execute Shell":

 echo Remote branch is $GIT_BRANCH, replacing origin with refs/heads. git push --follow-tags "$GIT_URL" "+HEAD:${GIT_BRANCH/#origin\//refs/heads/}" 
+1
source share

All Articles