Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As mentioned in "<a href="http://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/" rel="noreferrer">Polling must die: triggering Jenkins builds from a git hook</a>", you can notify Jenkins of a new commit:</p> <blockquote> <p>With the latest <a href="https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin" rel="noreferrer">Git plugin 1.1.14</a> (that I just release now), you can now do this more >easily by simply executing the following command:</p> <pre><code>curl http://yourserver/jenkins/git/notifyCommit?url=&lt;URL of the Git repository&gt; </code></pre> <p>This will scan all the jobs that’s configured to check out the specified URL, and if they are also configured with polling, it’ll immediately trigger the polling (and if that finds a change worth a build, a build will be triggered in turn.) </p> <p>This allows a script to remain the same when jobs come and go in Jenkins.<br> Or if you have multiple repositories under a single repository host application (such as Gitosis), you can share a single post-receive hook script with all the repositories. Finally, this URL doesn’t require authentication even for secured Jenkins, because the server doesn’t directly use anything that the client is sending. It runs polling to verify that there is a change, before it actually starts a build.</p> </blockquote> <p>As <a href="http://jenkins.361315.n4.nabble.com/triggering-Jenkins-builds-from-a-git-hook-td4173543.html" rel="noreferrer">mentioned here</a>, make sure to use the right address for your Jenkins server:</p> <blockquote> <p>since we're running Jenkins as standalone Webserver on port 8080 the URL should have been without the <code>/jenkins</code>, like this: </p> <pre><code>http://jenkins:8080/git/notifyCommit?url=git@gitserver:tools/common.git </code></pre> </blockquote> <p>To reinforce that last point, <a href="https://stackoverflow.com/users/1860867/ptha">ptha</a> adds <a href="https://stackoverflow.com/questions/12794568/how-to-configure-git-post-commit-hook/12794930#comment50886496_12794930">in the comments</a>:</p> <blockquote> <p>It may be obvious, but I had issues with: </p> <pre><code>curl http://yourserver/jenkins/git/notifyCommit?url=&lt;URL of the Git repository&gt;. </code></pre> <p>The <strong>url</strong> parameter should match exactly what you have in <strong>Repository URL</strong> of your Jenkins job.<br> When copying examples I left out the protocol, in our case <code>ssh://</code>, and it didn't work.</p> </blockquote> <hr> <p>You can also use a simple post-receive hook like in "<a href="http://blog.avisi.nl/2012/01/13/push-based-builds-using-jenkins-and-git/" rel="noreferrer">Push based builds using Jenkins and GIT</a>"</p> <pre><code>#!/bin/bash /usr/bin/curl --user USERNAME:PASS -s \ http://jenkinsci/job/PROJECTNAME/build?token=1qaz2wsx </code></pre> <blockquote> <p>Configure your Jenkins job to be able to “Trigger builds remotely” and use an authentication token (<code>1qaz2wsx</code> in this example).</p> </blockquote> <p>However, this is a project-specific script, and the author mentions a way to generalize it.<br> The first solution is easier as it doesn't depend on authentication or a specific project.</p> <hr> <blockquote> <p>I want to check in change set whether at least one java file is there the build should start.<br> Suppose the developers changed only XML files or property files, then the build should not start. </p> </blockquote> <p>Basically, your build script can:</p> <ul> <li>put a 'build' notes (see <a href="http://git-scm.com/docs/git-notes" rel="noreferrer"><code>git notes</code></a>) on the first call</li> <li>on the subsequent calls, grab the list of commits between <code>HEAD</code> of your branch candidate for build and the commit referenced by the <code>git notes</code> 'build' (<code>git show refs/notes/build</code>): <code>git diff --name-only SHA_build HEAD</code>.</li> <li>your script can parse that list and decide if it needs to go on with the build. </li> <li>in any case, create/move your <code>git notes</code> '<code>build</code>' to <code>HEAD</code>.</li> </ul> <hr> <p>May 2016: <a href="https://stackoverflow.com/users/2160028/cwhsu">cwhsu</a> points out <a href="https://stackoverflow.com/questions/12794568/how-to-configure-git-post-commit-hook/12794930#comment61593376_12794930">in the comments</a> the following possible url:</p> <blockquote> <p>you could just use <code>curl --user USER:PWD http://JENKINS_SERVER/job/JOB_NAME/build?token=YOUR_TOKEN</code> if you set trigger config in your item</p> </blockquote> <p><a href="https://i.stack.imgur.com/Hc7Ps.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Hc7Ps.png" alt="http://i.imgur.com/IolrOOj.png"></a></p> <hr> <p>June 2016, <a href="https://stackoverflow.com/users/255931/polaretto">polaretto</a> points out <a href="https://stackoverflow.com/questions/12794568/how-to-configure-git-post-commit-hook/12794930#comment61946577_12794930">in the comments</a>:</p> <blockquote> <p>I wanted to add that with just a little of shell scripting you can avoid manual url configuration, especially if you have many repositories under a common directory.<br> For example I used these parameter expansions to get the repo name </p> <pre><code>repository=${PWD%/hooks}; repository=${repository##*/} </code></pre> <p>and then use it like:</p> <pre><code>curl $JENKINS_URL/git/notifyCommit?url=$GIT_URL/$repository </code></pre> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload