How to post votes on custom labels from jenkins gerrit trigger?
The question is quite old, but I faced the same problem and want to share my solution:
Install the Groovy Postbuild Plugin: https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin
Use the following script as PostBuild-Action.
It will do for you:
- collect necessary environment variables and status of the job
- build feedback message
- build ssh command
execute ssh command -> send feedback to gerrit
//Collect all environment variables of the current build job def env = manager.build.getEnvironment(manager.listener) //Get Gerrit Change Number def change = env['GERRIT_CHANGE_NUMBER'] //Get Gerrit Patch Number def patch = env['GERRIT_PATCHSET_NUMBER'] //Get Url to current job def buildUrl = env['BUILD_URL'] //Build Url to console output def buildConsoleUrl = buildUrl + "/console" //Verification will set to succeded (+1) and feedback message will be generated... def result = +1 def message = "\\\"Static code analysis succeeded - ${buildUrl}\\\"" //...except job failed (-1)... if (manager.build.result.isWorseThan(hudson.model.Result.SUCCESS)){ result = -1 message = "\\\"Static code analysis failed - ${buildUrl}\\\"" } //...or job was aborted if (manager.build.result == hudson.model.Result.ABORTED){ result = 0 message = "\\\"Static code analysis aborted - ${buildConsoleUrl}\\\"" } //Send Feedback to Gerrit via ssh //-i - Path to private ssh key def ssh_message = "ssh -i /path/to/jenkins/.ssh/key -p 29418 user@gerrit-host gerrit review ${change},${patch} --label=customLabel=${result} --message=${message}" manager.listener.logger.println(new ProcessBuilder('bash','-c',"${ssh_message}").redirectErrorStream(true).start().text)
I hope this will help you to solve your challenge without using the Gerrit Trigger Plugin to report
I'm posting +1/-1 on a custom label by changing the commands in the advanced section of the gerrit trigger configuration to e.g.
gerrit review <CHANGE>,<PATCHSET> --message 'Build Successful <BUILDS_STATS>' --label 'MyCustomVerifiedLabel=<VERIFIED>' --code-review <CODE_REVIEW>
The $ENV_VAR syntax is only usable for build started messages as that's the only time that there is the possibility of only one build in the context.
The plugin is currently (v. 2.12) a bit opinionated about what review labels that it knows about, it's assuming verified and code review. But by editing the verified commands you can change what verified and code review in Jenkins means in Gerrit. For example
gerrit review <CHANGE>,<PATCHSET> --message 'Build Successful <BUILDS_STATS>' --acceptance-tests <VERIFIED> --code-quality <CODE_REVIEW>
There have been talks among the developers of the plugin to add configurable label support, but the code review and verified assumptions runs deep in the code so its not an easy fix.