Reputation: 33
How can I configure a parametrized build in Jenkins with git Commit id? I have two parameters:
I just want to build in Jenkins with Commit Id.... As i can Build with Tag....
Upvotes: 3
Views: 5855
Reputation: 22101
TL;DR
You can pass the Commit-Id as a parameter in the branch specifier section
So, the Answer would be:
$COMMIT_ID
LONG ANSWER
I wanted to do the same. Allow the user to specify the Branch Name and the Commit Id. I tried the answer provide by @Forest and I was receiving the error:
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
On checking the Help for Branch Specifier, I found that it was possible to pass the Commit Id as a standalone parameter.
But my concern here was that if I merge two branches, which branch would it pick the commit from (Noob thought).
A commit actually exists on a single branch. Even if two branches are merged, the commit is technically part of the original branch it was committed to. It is easy to visualise this if you see the flow graph of two merged branches.
Upvotes: 0
Reputation: 383
Yes you can parameterize your build with two string paramaters (BRANCH_NAME and COMMIT_ID). You should enter a default for the branch, so that whatever branch you use most (hopefully master) is automatically populated. Defining parameters is discussed in detail here.
In the branch specifier section (under branches to build) enter the following:
*/$BRANCH_NAME $COMMIT_ID
This will make it so instead of "Build" you will have "Build with Parameters". Manually triggering the build will cause you to be prompted to enter the branch name and commit. For the commit, you can either enter the whole hash or just the first 7 characters.
Upvotes: 2