Let Jenkins build project from a Mercurial commit

混江龙づ霸主 提交于 2019-12-06 00:36:44

问题


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.


回答1:


  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



回答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




回答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.



来源:https://stackoverflow.com/questions/19299120/let-jenkins-build-project-from-a-mercurial-commit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!