user2367078
user2367078

Reputation: 405

In Jenkins is there any easy way to build from a specify GIT SHA ID?

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

Upvotes: 2

Views: 2734

Answers (1)

Florian Castellane
Florian Castellane

Reputation: 1225

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://[email protected]:/myrepo.git and sha1 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12:

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

https://foo.bar.com/jenkins/git/notifyCommit?url=ssh://[email protected]:/myrepo.git&sha1=2fd4e1c67a2d28fced849ee1bb76e7391b93eb12

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

Upvotes: 2

Related Questions