How to specify a Git tag to be processed with Jenkins
TweetPosted on Friday Feb 21, 2014 at 08:35PM in Jenkins
Environment
- Jenkins 1.551
- Apache Maven 3.1.1
- git version 1.8.3.4 (Apple Git-47)
- Eclipse Kepler SR1
- Oracle JDK7u51
- OS X 10.9.1
Create a tag
Open context menu of the project - Team - Advanced - Tag
Enter tag name and Tag message, then click OK
To check created tag, Open context menu of the project - Team - Show in Repositories View
Confirm it appeared.
Modify a resource of HEAD
- In order to check that build will processed with the tag specified, so just do some modify a resource of HEAD.
- Make sure that you are in the master branch.
- Procedure to switch: Team - Switch To - master
- I have modified a resource that returns a message to Servlet. now it shows like that:
- After modify, we have to commit it.
Install Git Parameter Plugin
I got trouble that the plugin not showing any tags, so I have stopped using this plugin. there are some people who reporting same problem[6]. If skipped this, we can't see the list of tags in the repository, but we can specify a tag manually.
This plugin makes easy that specify a tag to be processed.
Make a Jenkins job
- Copy a job that created in previous post
- Check “This build is parameterized”
- Click “Add Parameter”
- Click “Git Parameter”
- Enter “tag” to “Name”
- Enter “*/master” to “Branch”
- Find the section named “Source Code Management”
- Enter “${tag}” to “Branch Specifier”
- Click “Save”
Try Parameterized build
- Click this:
- Select a tag that created above
- Click “ビルド”
Check console output of Jenkins
ユーザーanonymousが実行 ビルドします。 ワークスペース: /Users/Shared/Jenkins/Home/jobs/DeploySpecifiedTag/workspace Fetching changes from the remote Git repository Fetching upstream changes from file:///Users/kyle/gits1/hellojenkins Checking out Revision 9d88b2abe381c6e2c915bbbf0ddeec09119b6f04 (v1.0) Parsing POMs ...
- We can see that build was processed with tag named “v1.0”
References
- Can I get Jenkins to build a git tag from a passed in parameter? - Stack Overflow
- Jenkins and the Git Branch Selection - Sourceprojects.org
- Git Parameter Plugin - Jenkins - Jenkins Wiki
- Jenkinsで外部パラメータで与えたブランチを対象にビルドできるようにしておくと凄惨性あがって墓ドル - ( ꒪⌓꒪) ゆるよろ日記
- Hudson Growl Pluginでビルド結果をGrowlへ通知 | skmks
- Doesn't show any tags or revisions · Issue #2 · lukanus/git-parameter
Tags: jenkins
How to make git commit to trigger run a Jenkins job
TweetPosted on Friday Feb 21, 2014 at 06:02PM in Technology
Environment
- Jenkins 1.551
- git version 1.8.3.4 (Apple Git-47)
- OS X 10.9.1
Try using curl
- In this setup, there is no authentication at Jenkins.
curl -X POST http://localhost:18080/job/BuildAndTestHead/build
- Let's try with dump-header option.
kyle-no-MacBook:Jenkins kyle$ curl -D - -X POST http://localhost:18080/job/BuildAndTestHead/build HTTP/1.1 201 Created Location: http://localhost:18080/queue/item/4/ Content-Length: 0 Server: Jetty(8.y.z-SNAPSHOT) kyle-no-MacBook:Jenkins kyle$
Configure a hook of repository
- Create a file named “post-commit” in .git/hooks directory.
kyle-no-MacBook:hooks kyle$ pwd /Users/kyle/gits1/hellojenkins/.git/hooks kyle-no-MacBook:hooks kyle$ ls -l total 8 -rwxr-xr-x+ 1 kyle staff 73 2 23 10:50 post-commit kyle-no-MacBook:hooks kyle$ cat post-commit #!/bin/sh curl -X POST http://localhost:18080/job/BuildAndTestHead/build kyle-no-MacBook:hooks kyle$
- Now it runs automatically when we commit using git command from cli.
Remarks
- According to [3], It doesn't work when we commit with Eclipse.
- So, we might have to config Jenkins to poll the repository periodically.
References
Tags: jenkins