Gerrit checks api

Hi,
Does anyone have an example how to use the gerrit checks api plugin ?

The documentation in this plugin is thin - all I can see is rest api request to get results.
I would like to get an example from the beginning of process:

  • How I create a checker
  • How I can trigger a checker run / update results
  • Where an when I should register the app
  • If there is a jenkinsfile that defines this flow it will be great
    Thanks

Hello @chenarm and welcome to this community. :wave:

To use the Gerrit Checks API plugin, you could try to follow these (untested) steps:

  1. Create a Checker: A checker is a tool or process that performs checks on Gerrit changes. You can create a checker using the Gerrit REST API. Here’s an example using curl:
    curl -X PUT -d @checker.json --user <username>:<password> https://<gerrit-server>/a/plugins/checks/checkers/<checker-uuid>
    In the checker.json file, you can specify the properties of the checker:
{
  "name": "My Checker",
  "description": "This is my checker",
  "url": "http://my-checker-url",
  "repository": "my-repo",
  "status": "ENABLED"
}
  1. Trigger a Checker Run / Update Results: You can trigger a checker run and update the results using the Gerrit REST API. Here’s an example:
    curl -X POST -d @run.json --user <username>:<password> https://<gerrit-server>/a/changes/<change-id>/revisions/<revision-id>/runs
    In the run.json file, you can specify the properties of the run:
{
  "checker_uuid": "<checker-uuid>",
  "status": "RUNNING"
}

To update the results, you can use a similar curl command, but with the PUT method and the run ID in the URL:
curl -X PUT -d @result.json --user <username>:<password> https://<gerrit-server>/a/changes/<change-id>/revisions/<revision-id>/runs/<run-id>
In the result.json file, you can specify the results of the run:

{
  "status": "COMPLETED",
  "outcome": "SUCCESSFUL"
}
  1. Register the App: You need to register your app with Gerrit in order to use the Checks API. This can be done in the Gerrit settings under “OAuth”.
  2. Jenkinsfile: You can now define a pipeline that triggers a checker run and updates the results. Here’s a basic example:
pipeline {
    agent any

    stages {
        stage('Run Checker') {
            steps {
                script {
                    // Trigger checker run
                    gerritChecksPublish checksName: 'My Checker', gerritProject: 'my-repo', status: 'RUNNING'

                    // Run your checks here...

                    // Update results
                    gerritChecksPublish checksName: 'My Checker', gerritProject: 'my-repo', status: 'COMPLETED', details: 'All checks passed'
                }
            }
        }
    }
}

In this example, gerritChecksPublish is a step provided by the Gerrit Checks API Jenkins plugin. The checksName parameter is the name of your checker, and the gerritProject parameter is the name of your Gerrit project. The status parameter is the status of the checker run, and the details parameter is a message that describes the results of the checker run.

If this works for you, with or without modifications, please consider opening a pull request in the plugin repository, or in the jenkins.io repository for a blog post about this subject.

Hi @poddingue
Thank you very much for your answer.
Regarding the checkers plugin in gerrit - we have gerrit 3.6.6 on production and I don’t see it in the plugins list.

  1. Should I see that there ? or it comes automatically with the gerrit?
  2. If not - is the package the should be installed to get this plugin - pollygerrit-ui ?