Kohei Nozaki's blog 

How to specify a Git tag to be processed with Jenkins


Posted 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

  1. Open context menu of the project - Team - Advanced - Tag

  2. Enter tag name and Tag message, then click OK

  3. To check created tag, Open context menu of the project - Team - Show in Repositories View

  4. 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

  1. Copy a job that created in previous post
  2. Check “This build is parameterized”
  3. Click “Add Parameter”
  4. Click “Git Parameter”
  5. Enter “tag” to “Name”
  6. Enter “*/master” to “Branch”
  7. Find the section named “Source Code Management”
  8. Enter “${tag}” to “Branch Specifier”
  9. Click “Save”

Try Parameterized build

  1. Click this:
  2. Select a tag that created above
  3. 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

  1. Can I get Jenkins to build a git tag from a passed in parameter? - Stack Overflow
  2. Jenkins and the Git Branch Selection - Sourceprojects.org
  3. Git Parameter Plugin - Jenkins - Jenkins Wiki
  4. Jenkinsで外部パラメータで与えたブランチを対象にビルドできるようにしておくと凄惨性あがって墓ドル - ( ꒪⌓꒪) ゆるよろ日記
  5. Hudson Growl Pluginでビルド結果をGrowlへ通知 | skmks
  6. Doesn't show any tags or revisions · Issue #2 · lukanus/git-parameter