Question

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.

Was it helpful?

Solution 3

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.

OTHER TIPS

  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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top