I am new to Jenkins. How to trigger a build remotely from Jenkins?
Can anybody tell how to configure Git post commit hook?
My requirement is whenever changes are made in the Git repository for a particular project it will automatically start Jenkins build for that project.
In Jenkins trigger build section I selected trigger build remotely.
curl cmbuild.aln.com/jenkins/view/project name/job/myproject/buildwithparameters?Branch=feat-con
As mentioned in "Polling must die: triggering Jenkins builds from a git hook", you can notify Jenkins of a new commit:
With the latest Git plugin 1.1.14 (that I just release now), you can now do this more >easily by simply executing the following command:
curl http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>
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.)
This allows a script to remain the same when jobs come and go in Jenkins.
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.
As mentioned here, make sure to use the right address for your Jenkins server:
since we're running Jenkins as standalone Webserver on port 8080 the URL should have been without the
/jenkins, like this:
It may be obvious, but I had issues with:
curl http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>.
The url parameter should match exactly what you have in Repository URL of your Jenkins job.
When copying examples I left out the protocol, in our case
ssh://, and it didn't work.
You can also use a simple post-receive hook like in "Push based builds using Jenkins and GIT"
#!/bin/bash /usr/bin/curl --user USERNAME:PASS -s \ http://jenkinsci/job/PROJECTNAME/build?token=1qaz2wsx
Configure your Jenkins job to be able to “Trigger builds remotely” and use an authentication token (
1qaz2wsxin this example).
However, this is a project-specific script, and the author mentions a way to generalize it.
The first solution is easier as it doesn't depend on authentication or a specific project.
I want to check in change set whether at least one java file is there the build should start.
Suppose the developers changed only XML files or property files, then the build should not start.
Basically, you build script can:
git notes) on the first call
HEADof your branch candidate for build and the commit referenced by the
git notes'build' (
git show refs/notes/build):
git diff --name-only SHA_build HEAD.
you could just use
curl --user USER:PWD http://JENKINS_SERVER/job/JOB_NAME/build?token=YOUR_TOKENif you set trigger config in your item
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.
For example I used these parameter expansions to get the repo name
and then use it like: