What's the role of Change-Id in commit message - gerrit

Why Change-Id is important for gerrit ? What kind of problems it may have without Change-Id in the commit message ? We are using Change-Id in our commit message, but without knowing the exact reason. Our client wants to remove the Change-Id from commit message, they feel it doesn't contain any valuable information for the commit itself. So now I need to convince them the necessity of it. Could you please help ?

It is neccessary to group the different patch sets (versions) of a change together. Otherwise there is no reason between the first commit and its overworked versions. So although there's an option "Require Change-Id", which can be deactivated, it is strongly adviced to not do so. See also in the Gerrit Docs.

Related

Is there a way to get gerrit to reject commits without a JiRA ticket number?

How does an admin configure Gerrit to automatically reject commits without JiRA ticket number? I've read this documentation but not sure how to implement it on all branches in a specific repository (not all repos!). Do all users need to download the file and copy it to their local repository or how does it work? What I want to achieve is that git/gerrit automatically rejects a commit that are missing a JiRA ticket number - doesn't have to be valid, it's up to the team to control that the ticket number is valid.
The Jira plugin is based in the ITS plugin. These plugins have a association configuration that can be set to MANDATORY.
MANDATORY : One or more issue-ids are required in the git commit message, otherwise the git push will be rejected.
SUGGESTED : Whenever git commit message does not contain one or more issue-ids, a warning message is displayed as a suggestion on the client.
OPTIONAL : Issues-ids are liked when found on git commit message, no warning are displayed otherwise.
The below config example is taken from the Jira plugin documentation.
[commentLink "Jira"]
match = (\\[[A-Z][A-Z]+-[1-9][0-9]*\\])
html = "$1"
association = MANDATORY
The Git::Hooks is the best solution to this job.
See how to install and configure it here.
See more info about it here.

How to add descption to a given patchset in Gerrit?

I can create new patchset to a given Gerrit without issues.
However, I would like to describe what the patchset is about. I have been doing that as part of the commit message, as I commit -amend and push the new patchset with the revised comment.
Is there a well defined way of describing the patchset in the commit message, so Gerrit can automatically set its description? The only mentioning of the description I found so far was from this page:
https://gerrit-review.googlesource.com/Documentation/concept-patch-sets.html#_description
Heh, looks like I found a potential answer for my own question. :)
If I encode the push command with a %m= I seem to be able to set the description for the patchset. It feels a little hacky, in that I need to replace
spaces with _ and percent encode characters as well.
That is described gerrit's documentation for code review.
Example:
git push ssh://john.doe#git.example.com:29418/kernel/common HEAD:refs/for/experimental%m=This_is_a_rebase_on_master%21
Any other/better way that you may know about?

Jenkins trigger build on specific commit message of branch

I did a little search and googling for this issue, but most of the posts are related on how to isolate (by using git plugin etc.)
What I'm wondering is there a way to configure a jenkins job to trigger a build on specific commit message (let's say if it contains "build") on the branch I specified.
Thanks in advance,
You can use Commit Message Trigger Plugin to achieve this.
Once you install this plugin, go to your job configuration page and under Build Environment section check Enable Commit Message Trigger,then add the keyword that will cause the job to trigger.
The answers by #ANIL is totally correct just a few improvement to make thinks clear.
if you put the keyword as admin as shown in image then in your commit message you must
have "ci admin" included and it works. It didn't work without adding ci ahead of keywords in my commit message for me.
We don't have to add ci in keywords in the build environment setting.

Why is the gerrit change-id commit-hook not a push-hook?

Why is the default gerrit change-id commit-hook not a pre-push-hook?
The default Change-Id "commit-msg"-hook in gerrit adds a Change-Id to every commit. Why is in not implemented as a "pre-push"-hook? If it where it could add Change-Ids only to commits that are pushed to refs/for/...
With the current setup I get Change-Ids in commits that I want to push directly (without a review). It's ugly.
I think I know the answer now.
It would be bad practice for a pre-push hook to change the contents that is being pushed. It could block a push from happening but changing the commits and then automatically precede with the push without the user having a chance to review the changes is bad practice.

Serve custom commit-msg hook from Gerrit

Gerrit comes with a default commit message hook to insert a Change-Id in the footer. The hook defines that the Change-Id should be inserted after Issue or Bug in the footer:
CHANGE_ID_AFTER="Bug|Issue"
Now I would like to modify this so it becomes:
CHANGE_ID_AFTER="Refs|Closes|Fixes"
This is because the issue tracker in use doesn't work with Bug or Issue but with an issue identifier starting with a #.
Now of course I can apply this locally but uniformity is desired across the complete development team. It would help a lot if Gerrit would serve this modified file.
I can't seem to find anything in Gerrit's docs that describes what I would like to achieve.
Since the hook is pulled in through scp I thought I might be able to upload a modified hook the same way. This of course didn't work.
I have administrative rights to Gerrit, so that can't be the issue.

Resources