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...
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With