2

I am trying to set-up a Jenkins job to build from a specify GIT SHA-ID. By default it builds from the latest SHA-ID. I checked git-plugin and git parameter plugin but I can't find a way to specify SHA-ID.

I tried ry one of the solution mention in an OLD post "I'm not sure about Hudson, but Jenkins' Git Plugin has an "Advanced..." button at the right just above the "Repository browser" field. Clicking there reveals a lot of additional options, one of them being "Checkout/merge to local branch (optional)". Its help text says "If given, checkout the revision to build as HEAD on this branch. Please note that this has not been tested with submodules", so that seems to be what you have in mind."

But it didn't work

Thanks

user2367078
  • 395
  • 2
  • 5
  • 10
  • Possible duplicate of [Use Hudson to build a specific git commit](http://stackoverflow.com/questions/4207450/use-hudson-to-build-a-specific-git-commit) – Hackerman Jan 11 '16 at 20:49
  • I looked at it and try one of the solution mention in that post I'm not sure about Hudson, but Jenkins' Git Plugin has an "Advanced..." button at the right just above the "Repository browser" field. Clicking there reveals a lot of additional options, one of them being "Checkout/merge to local branch (optional)". Its help text says "If given, checkout the revision to build as HEAD on this branch. Please note that this has not been tested with submodules", so that seems to be what you have in mind." But it didn't work. – user2367078 Jan 11 '16 at 21:16
  • I don't want to give SHA ID in "Branch to build" as it will not set the HEAD to that specific SHA ID. – user2367078 Jan 11 '16 at 21:20
  • And even when I use SHA ID in 'Branches to Build" I got this error "Fetching changes from 1 remote Git repository Fetching upstream changes from origin Commencing build of Revision 7dc9188fbe692e123486f798fc2c66a0345ff948 (detached) Checking out Revision 7dc9188fbe692e123486f798fc2c66a0345ff948 (detached) FATAL: Could not delete branch 7dc9188fbe692e123486f798fc2c66a0345ff948 – user2367078 Jan 11 '16 at 21:27

1 Answers1

2

I can think of two solutions.

  1. Using parameters

Set up a string parameter (or better, a git hash parameter) for your job: jenkins git hash param config

Then set up the git checkout to use the same variable e.g. here $MY_GIT_HASH: configuring git hash in scm step

Then your job can be started manually by providing a revision.

  1. Using hooks

If your Jenkins job is configured to be triggered by SCM changes, you can trigger jobs using the REST API (using the same interface that you can use in e.g. git hooks).

For example, for git remote ssh://git@mygitserver.foobar.com:/myrepo.git and sha1 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12:

Hit this URL using your browser (or cURL in scripts)

https://foo.bar.com/jenkins/git/notifyCommit?url=ssh://git@mygitserver.foobar.com:/myrepo.git&sha1=2fd4e1c67a2d28fced849ee1bb76e7391b93eb12

This will schedule all jobs configured to use this repo to start building this specific hash.

Florian Castellane
  • 1,197
  • 2
  • 14
  • 38