Gerrit Reviewers name and email in Jenkins - jenkins

I am trying to integrate Gerrit Code Review with Jenkins and I need to get an email names of all Reviewers that are assigned to a change that triggered Jenkins job.
I have found this fragment of Gerrit Code Review plugin with all environmental variables listed, but there is nothing about reviewers.
My goal: send email notification about job status (in Jenkins job Post-Actions via email-ext plugin) to change owner, reviewers patchset creators and job owner.
My question is: is there any way of obtaining Gerrit Reviewers emails and parsing them into Jenkins as a variable?

You can use the REST API, like in the following example:
curl --silent --user USER:PASS --request GET https://GERRIT-SERVER/a/changes/CHANGE-NUMBER/reviewers | sed 1d | jq --raw-output '.[].email'
See more info on Gerrit documentation here.

Related

How can I get the PR reviewers email address in jenkins job

I'm running a jenkins job to generate a report. Post the build I wan to sent that report to the person reviewed the PR. How can I achieve this using bitbucket and jenkins. Only the reviewer should get the report.
There is no such plugin to give you details of PR reviewer. Github Pull Request Builder plugin expose a limited number of environment variable. But you can try to write simple script or command to use Github API.
As you are using Bitbucket you can do something similar using BB API (link)
curl -X GET -u "user:pass" "https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pullrequests/{pull_request_id}" | jq '.participants[] | select(.state=="approved")| .user.display_name'
With above curl command you will get display name of your PR approvers. You can not fetch any users email using BB API, so if it is under your company you may create a file having display name to email mapping and source it to send emails.

Can't report +1 to gerrit server via jenkins

I tried to build CI on my system. The Jenkins could listen gerrit push event and checkout the code. But jenkins Gerrit-Trigger not reporting +1 verified after successful job run.
There is an error message in Console Output: ERROR Gerrit response: HTTP method POST is not supported by this URLFinished: SUCCESS
Versions:
Windows 10
Jenkins 2.263.1
Gerrit 2.10.2
Gerrit Trigger Plugin 2.32.0
Git Plugin 4.5.0
There are some warning, does it matter?
My item Gerrit Reporting Values:
EDIT
The Error message doesn't show again after modifying --message Message to double quotes (Manage Jenkins > Gerrit Trigger > Gerrit Verified Commands)
EDIT
Some things you should consider:
Your Gerrit version is (really) too old, it would be very good if you update to a newer version.
Try to uncheck the "Use REST API" option at Manage Jenkins > Gerrit Trigger > Advanced > REST API. Maybe the Gerrit 2.10.2 REST API isn't compatible with the Gerrit-Trigger last version.
Do you have the "Code-Review" and the "Verified" labels defined on Gerrit? Does the Gerrit user used by Jenkins have permission to perform the review (-1/+1)?

How to trigger Multibranch job using bash scripting?

Tried looking for Trigger builds remotely (e.g., from scripts) option, but the only option available is Periodically if not otherwise run. Need to run trigger multibranch specific job for specific branch using curl from the local machine.
This should be possible like this:
curl -X POST -u <jenkins_user>:<jenkins_secret> <jenkins_url>/job/<multibranch_pipeline_name>/job/<branch_name>/build

How do I send jenkins build log as an attachment to a slack channel and JIRA

I want to have the option to send the whole jenkins build log to a slack channel. I currently output the status of the builds successfully to slack, I would like to send the build log if the build fails. Does anyone know how to do this?
I have tried creating a shell script to zip up the log on the jenkins server and then posting it.
You can use Incoming WebHooks or Slash Commands both are the same.
I'm also using both for sending my Jenkins to build artifact to slack channel but.
You can add an attachment also in this hooks or Jenkins generate URL for all build artifacts and you can just pass that URL on slack and user can download it via slack.
you have to user slack plugin on Jenkins and configure your slack token and stuff like that.
If you need more detail contact me.

Sending email to git culprits or committer who broke the build with ext-email plugin

I have jenkins setup where POST HOOKS trigger a SCM polling job and the polling job triggers build flow job and build flow job calls various other jobs.
The git plugin mentions that we can use GIT_COMMITTER_EMAIL and GIT_AUTHOR_EMAIL environment variables, but i get the value as null. Since I am unable to set the commiter's email here, I am not able to propagate the email address to all other jobs which doesn't have git information.
Another post mentions about sending email to culprits with ext-email plugin, but that doesn't work too.
Any ideas on how to get the git committer info or culprit information ?

Resources