Dear Gerrit community,
during the last Gerrit User Summit I presented a first version of the Checks API
implementation for Jenkins CI servers. In the meantime, the plugin on Gerrit and
Jenkins-side were released and can be used.
How does it work?In your Jenkins server you will need to install the Gerrit-Checks-Api plugin [1].
This plugin uses a Lucene index provided by the Lucene-search plugin [2], which is
installed as a dependency, to provide a REST API endpoint allowing to query for
builds (Runs) working on a patchset.
If you haven't used the Lucene-search plugin yet, you will have to build the
index once following the procedure described in [3]. Afterwards, the plugin will
add new builds automatically to the index.
The Jenkins server also needs to support CORS-requests coming from Gerrit. Since
Jenkins does not support that itself, a proxy like Nginx has to be used to add
the necessary headers to the request. An example on how to do this can be found
in [4].
In Gerrit, install the checks-jenkins plugin (e.g. for Gerrit 3.7 [5]). To enable
the plugin for a project, add a file called `checks-jenkins.config` to the project's
`refs/meta/config`-branch, containing the URL of the Jenkins-server(s):
```
[jenkins "gerrit-ci"]
url =
https://gerrit-ci.gerritforge.com```
The Checks-tab should now be visible in the Change Screen of Gerrit's UI and
display the data for builds run on the current patchset.
Note, that if the Jenkins instance does not allow anonymous access, the user has
to be logged into Jenkins with the same browser (The Jenkins UI does not have to
be open in a different tab). Otherwise, the plugin will not have the authorization
to access the data in Jenkins.
Why do I need another plugin on Jenkins?The need for further required plugins arises due to how the remote API of Jenkins
core works and the existing Gerrit plugins.
Jenkins core does not include an index. Thus, searching for builds with certain
parameters is not efficient. Further, the remote access API provided by Jenkins [6]
does not allow to query but exposes a tree-like structure that can be navigated.
Thus, to get all builds working on a given patchset, each request would have to
look at every build of relevant jobs. On large Jenkins instances this would cause
quite some load, especially with a lot of clients trying to fetch this data with
regular polls. Thus, a more efficient way of finding relevant builds was required.
The lucene-search plugin provided that by providing a Lucene-index that allows to
query for builds, but did not expose a REST API and of course did not contain
Gerrit-specific knowledge.
So why not extend existing Gerrit-plugins for Jenkins, i.e. gerrit-trigger and
gerrit-code-review? As there are two completely independent plugins which might
even both be used on the same server, this would not work. In Jenkins, two plugins
cannot provide the same REST API endpoint. Having two different REST API endpoints
for mostly the same use case would not be nice. Also this would have required
double maintenance of the REST-API code.
For these reasons, I decided to create a separate plugin instead.
What are the current limitations?- Unfortunately, the lucene-search plugin does not yet support Java 11 and with
it newer Jenkins versions (> 2.357). I have started working on changing that,
but this requires a Lucene update over a lot of versions with a lot of breaking
changes, so it might take me some time to get this done.
- The lucene-search plugin currently enforces the use of its search-functionality
in the Gerrit UI, which might not be desired by users. I have already created
a PR [7] to make this optional, but did not receive any feedback yet.
What is planned next?- Allow to proxy requests through the Gerrit backend to avoid CORS.
- Support jobs that neither use the gerrit-trigger plugin nor the gerrit-code-review
plugin, but still work on a patchset.
- Add more data to the report (e.g. test results)
I am looking forward to your feedback and as always contributions are more than
welcome!
Best Regards,
Thomas
[1]
https://plugins.jenkins.io/gerrit-checks-api/[2]
https://plugins.jenkins.io/lucene-search/[3]
https://plugins.jenkins.io/lucene-search/#plugin-content-database-rebuild[4]
https://enable-cors.org/server_nginx.html[5]
https://gerrit-ci.gerritforge.com/view/Plugins-stable-3.7/job/plugin-checks-jenkins-bazel-master-stable-3.7/[6]
https://www.jenkins.io/doc/book/using/remote-access-api/[7]
https://github.com/jenkinsci/lucene-search-plugin/pull/57