Let Jenkins build project from a Mercurial commit
Asked Answered
K

3

6

Is there a way to specify a hook in the single repository?

Now we have specified the hook in the "/etc/mercurial/hgrc" file, but every time it builds twice, and it builds for each commit in each repository.

So we want to specify a build per repository.

This is how we implemented the hook:

[hooks]
changegroup = curl --silent http://jenkins:8080/job/ourProject/build

It's on a Ubuntu server.

Krystin answered 10/10, 2013 at 14:50 Comment(2)
If you have a lot of projects an easier way might be to use a Community edition of web interface (RhodeCode) that allows nicer Jenkins management Please see here: #41036344Vitkun
Does this answer your question? Jenkins build after mercurial commitAcetometer
W
0

Ok, I found what I looked for (I'm the bounty; my case is Mercurial with a specific branch).

In the main/origin repository, place a hook with your desired build script. Pregroupchange is to maintain the incoming changes. I have a rhodecode installed on the main repository and itself has its own hooks.

In this way, I still trigger Jenkins and still have the changes afther the trigger for rhodecode push notifications and others.

[hooks]
pregroupchange = /path/to/script.extention

In the script, place your desired actions, also a trigger for Jenkins. Don't forget to enable in Jenkins:Job:Configure:Build Triggers:checkbox Trigger builds remotely + put here your desired_token (for my case: Mercurial).

Because you can't trigger only to a specific branch in Mercurial, I found the branch name in this way. Also, to trigger from a remote script, you need to give in Jenkins read permission for anonymous overall, or create a specific user with credentials and put them into the trigger URL.

Bash example:

#!/bin/bash
BRANCH_NAME=`hg tip --template "{branch}"`
if [ $BRANCH_NAME = "branch_name" ]; then
   curl --silent http://jenkins_domain:port/path/to/job?token=desired_token
fi

For the original question:

In this way you only execute one build, for a desired branch. Hooks are meant only for the main repository in case you work with multiple clones and multiple developers. You may have your local hooks, but don't trigger Jenkins from you local, for every developer. Trigger Jenkins only from the main repository when a push came (commit, incoming, and groupchange). Your local hooks are for other things, like email, logs, configuration, etc.

Weighin answered 13/3, 2015 at 7:27 Comment(0)
W
7
  1. Select the Poll SCM option under Build Triggers.
  2. Make sure that schedule form is empty.

You should be creating in the .hg directory, /home/user/mercurial/.hg/hgrc and add hooks as:

[hooks]
commit.jenkins = wget -q http://localhost:8080/mercurial/notifyCommit?url=file:///home/user/mercurial > /dev/null
incoming.jenkins = wget -q http://localhost:8080/mercurial/notifyCommit?url=file:///home/user/mercurial > /dev/null
Wore answered 12/3, 2015 at 8:44 Comment(3)
The first step (tick the poll SCM) is what made the difference for me! Thanks.Hanes
As @Hanes said I too had to tick poll SCM to get this to work. I also had to remove any schedules otherwise it wouldn't trigger straight away.Ormolu
Another answer says "make sure that your Jenkins project doesn't poll". Isn't that a contradiction?Chamkis
D
2

You should make sure that

  1. Your Jenkins project doesn't poll

  2. You use the proper notifyCommit URLs for your Mercurial hooks: https://wiki.jenkins-ci.org/display/JENKINS/Mercurial+Plugin

Dragonroot answered 11/10, 2013 at 13:35 Comment(1)
Jenkins doesn't poll, the plugin is installed, it works when i open the url in the browser, but it doesn't work on push.Krystin
W
0

Ok, I found what I looked for (I'm the bounty; my case is Mercurial with a specific branch).

In the main/origin repository, place a hook with your desired build script. Pregroupchange is to maintain the incoming changes. I have a rhodecode installed on the main repository and itself has its own hooks.

In this way, I still trigger Jenkins and still have the changes afther the trigger for rhodecode push notifications and others.

[hooks]
pregroupchange = /path/to/script.extention

In the script, place your desired actions, also a trigger for Jenkins. Don't forget to enable in Jenkins:Job:Configure:Build Triggers:checkbox Trigger builds remotely + put here your desired_token (for my case: Mercurial).

Because you can't trigger only to a specific branch in Mercurial, I found the branch name in this way. Also, to trigger from a remote script, you need to give in Jenkins read permission for anonymous overall, or create a specific user with credentials and put them into the trigger URL.

Bash example:

#!/bin/bash
BRANCH_NAME=`hg tip --template "{branch}"`
if [ $BRANCH_NAME = "branch_name" ]; then
   curl --silent http://jenkins_domain:port/path/to/job?token=desired_token
fi

For the original question:

In this way you only execute one build, for a desired branch. Hooks are meant only for the main repository in case you work with multiple clones and multiple developers. You may have your local hooks, but don't trigger Jenkins from you local, for every developer. Trigger Jenkins only from the main repository when a push came (commit, incoming, and groupchange). Your local hooks are for other things, like email, logs, configuration, etc.

Weighin answered 13/3, 2015 at 7:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.