1

I'm in the process of setting up Git/Jenkins for a new project at work. It's the first time anyone at work has used either of these tools (currently we're using SVN and a custom build system). I've managed to get a system working; a developer does a commit, pushes to an origin/develop branch which triggers a Jenkins job using a post-receive trigger then Jenkins runs a number of testing jobs. If the tests pass, Jenkins does a push to origin/master.

This is working fine, but the problem is what happens when a build fails. A requirement is that the origin/master and origin/develop branches should be the same. So when a build fails, origin/develop should be reset to the same revision as origin/master. Again, I can do this using the following commands (this is part of another Jenkins job which is triggered on a failed build):

git checkout develop
git reset --hard origin/master
git push -f

This resets the branch correctly and all is well. Except for one thing. Git sees this new push to the develop branch and triggers a new build.

So my questions is, how do I reset the develop branch to the master branch and tell Git to not trigger a build? The end goal is to reset the branch, I'm open on the mechanics. I can think of a couple of ways: add some information that the post-receive hook can pick up, however my research seems to suggest you can't pass parameters to hooks. Since there's no commit being done I can't use info from the last commit. Am I better off putting something in the triggered Jenkins build to abort if it somehow detects a rollback? Any ideas would be welcome.

One other thought. Is there a need to rollback develop at all? What happens if another push is made to origin/develop? Will it overwrite what's already there, add to it or just fail? Developers will be pulling from origin/master before making changes. The whole branching thing in Git confuses me a bit.

Justin
  • 384
  • 2
  • 14

1 Answers1

2

Instead of Jenkins monitoring origin/development, it could monitor another branch (like build)

Then you can add a post-receive hook which would monitor new commits on the development branch and:

  • if it detects a forced push, does nothing
  • it if detects a regular push (new commits being added), it reset the build branch on development new HEAD.
    That reset will make Jenkins trigger a new build on the build branch.

If the build fails, you leave the build branch untouched (to not trigger anything), but you reset development branch as many time as you want.

The idea is to add an intermediate level of control between your developers (pushing commits) and your build (done by Jenkins)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250