Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Committing data to Mercurial at the end of a build

I have a build script that is triggered by Jenkins. First Jenkins will get the latest version from the repo (Bitbucket) and then it will initiate the build script. Now if the build script is started in 'release' mode the script will make changes to some files (to keep track of version numbers and build dates, and to create a tag on the repo) These changes need to be pushed back up to the remote repo.

How do I implement this? The build takes a couple of minutes, so if someone pushes to the remote repo during the build then the push will fail because a merge is needed first. If that was not the case the merge will fail because there was nothing to merge...

like image 598
JeroenVandezande Avatar asked Oct 24 '13 09:10

JeroenVandezande


1 Answers

Consider having Jenkins do its commits in a named branch all its own. This has a lot of advantages -- the biggest being that Jenkins never has to worry about someone else pushing a change to the release branch -- only Jenkins will be. Your Jenkins build script could look something like this:

hg clone --updaterev release http://path/to/repo
hg merge default || true   # merge the latest from master
...build here...
hg commit -m "Auto commit from Jenkins for build $BUILDNUMBER" || true
hg tag build_$BUILDNUMBER
hg push

With a setup like that you're getting some advantages:

  • failed builds aren't creating new commits
  • Jenkins's push will always succeed
  • Jenkins's tag commits are in the 'release' branch, but still accessible from the default branch

Notice that the || true tells Jenkins not to fail the build on non-zero exit codes for merge (if there's nothing to merge) and nothing to commit.

Instead of cloning fresh each time you could just hg pull ; hg update -C release but for repos of reasonable size I like to start w/ a guaranteed clean slate.

like image 124
Ry4an Brase Avatar answered Oct 12 '22 10:10

Ry4an Brase