I want to use mercurial hooks to trigger regression builds (in Jenkins) when developers push from their local repos to a central, remote repo.
In path/to/repo/.hg/hgrc
[hooks]
changegroup = python:jenkins.py:trigger_build
And jenkins.py:
def trigger_build(ui, repo, source, hooktype, node, **Kwargs):
...
changeset_to_build = node
...
But in this case, node refers to the earliest changeset in the changegroup, I want to kick off building and testing against the most recent. I have a workaround that uses:
def trigger_build(ui, repo, source, hooktype, node, **Kwargs):
...
changeset_to_build = repo['default'].hex()
...
This gets the appropriate changeset, but I'm not sure it's the best way of doing this. Is there a more standard idiom that I'm missing?
Thanks
it seems to me that repo['default']
is always the head of the default branch. that could be a problem if developers expect builds for other branches or the default branch is not named default.
in a hook based on bash and revsets, i'd use the following:
#!/bin/bash
changeset_to_build=$(hg log --rev "heads(${HG_NODE}:)" --limit 1 --template "{node}")
that would be the first node without child changeset between HG_NODE and tip; so even if the changegroup does not start in the default branch, it is the head of the changegroup that jenkins should build.