How to do an automatic build for every commit/tag/push etc on a repository with Mercurial on Jenkins?

312 Views Asked by At

My goal from all this is to have Jenkins build every time someone does some sort of change to the repo(i.e tagging or commit).

In my .hg/hgrc file on TortoiseHg I included several different hooks in my repository settings. Those hooks have the following types: changegroup, commit, incoming, and tag. The command are written like wget <jenkins root>/mercurial/notifyCommit?url=<repository remote url> However whenever I do some sort of commit or tag etc, nothing happens. However if I go on the terminal and type in that same hook command(except i omit the type of hook im using) then it appears that Jenkins is aware of the change. I can verify this by going to my system log on Jenkins. It tells me that "Triggering polling of main after event from Ip address. In Jenkins I have Mercurial checked off as the source code management along with Trigger builds remotely and Generic Webhook Trigger. The only thing I figured out was that if I used the command start <url> then it will open a blank tab before running the build. Based off that I was thinking I could have a batch file that executes the wget and start command but I feel like I am overdoing this and that there should be an easier way to trigger a build from every time I do some sort of change to the repo

1

There are 1 best solutions below

0
Dmitry Sokolov On

You need to create a token (https://www.jenkins.io/blog/2018/07/02/new-api-token-system/), and add it to a job settings (https://humanwhocodes.com/blog/2015/10/triggering-jenkins-builds-by-url).

Then you can trigger a build using REST API, see https://www.jenkins.io/doc/book/system-administration/authenticating-scripted-clients/.

wget --auth-no-challenge \
    --user=user --password=apiToken \
    http://jenkins.yourcompany.com/job/your_job/build

So, you can trigger a build from a VCS hook.