2

Is there a way to configure Jenkins and the Git Publisher add-on to tag a revision that's not at the head of the master branch?

We would like to manage our integration process with a couple of steps that validate our software in sequence, and to facilitate this in an automated way by tagging the latest revision that has passed the first step, then adding another tag to that revision when it passes the second step. It's possible that some later revision might in the meantime have failed the first step or something, so that we aren't adding the tag to the head anymore. There are some other scenarios that we envision that also might call for such non-head tagging, as well.

I've tried checking out the desired tag in the Execute Command step or by specifying the tag in the Git SCM Branch field, but I keep hitting a non-ff merge error because I can't pull or rebase after the tag is applied.

The only change being pushed is the tag being added.

Is this possible?

Here's what's in the console output:

 > /usr/bin/git tag -l test-tag
 > /usr/bin/git tag -a -f -m Testing tag built from environment variable test-tag
Pushing tag test-tag to repo origin
 > /usr/bin/git config --get remote.origin.url
 > /usr/bin/git push ssh://jenkins@ncs-gerrit.inhouse.com:29418/ncs-test test-tag
ERROR: Failed to push tag test-tag to origin
hudson.plugins.git.GitException: Command "/usr/bin/git push ssh://jenkins@ncs-gerrit.inhouse.com:29418/ncs-test test-tag" returned status code 1:
stdout: 
stderr: To ssh://jenkins@ncs-gerrit.inhouse.com:29418/ncs-test
 ! [rejected]        test-tag -> test-tag (non-fast-forward)
error: failed to push some refs to 'ssh://jenkins@ncs-gerrit.inhouse.com:29418/ncs-test'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.
Scott
  • 1,247
  • 3
  • 10
  • 21

1 Answers1

0

This isn't yet available, but there is a ticket for it:

https://issues.jenkins-ci.org/browse/JENKINS-22499

After a few days of head scratching, I've discovered workaround based on this question:

Cache the git credentials on the jenkins box:

$ git config --global credential.helper 'cache --timeout 600'

which makes the credentials available to the Execute Shell build step in Jenkins:

$ /usr/local/bin/git tag -a "v${APPLICATION_VERSION}(${BUILD_DISPLAY_NAME})" ${GIT_COMMIT} -m "Tag at ${BUILD_ID}"
$ /usr/local/bin/git push Bitbucket "v${APPLICATION_VERSION}(${BUILD_DISPLAY_NAME})"

(Note: The APPLICATION_VERSION and GIT_COMMIT variables have been set by an upstream job)

Custard
  • 766
  • 1
  • 7
  • 15