Repo Jenkins library
Rebo jenkins lib is shared library for Jenkins that helps with basic operations with Gerrit over git and repo managed projects.
source: https://gitea.amarulasolutions.com/i-tools/repo_jenkins_lib
source: https://gerrit-review.amarulasolutions.com/admin/repos/i-tools/repo_jenkins_lib
configured as:
name: repo_jenkins_lib
load implicitly: true
allow default version to be overridden: true
Installation
Generate password for Gerrit REST API
Create password for your Gerrit bot user and add it to Jenkins. You can use gerrit REST API to generate the password:
curl -X PUT \
--user <admin username>:<admin password> \
--header "Content-Type: application/json; charset=UTF-8" \
-d "{\"generate\": true}" \
https://gerrit-review.amarulasolutions.com/a/accounts/<gerrit bot user id>/password.http
Add the credentials to Jenkins:
go to “Credentials” -> “System”
use “Add Credentials”
Kind: “Username with password”
Username: gerrit bot username
Password: gerrit bot REST API password
ID: e.g. jenkins-builder-amarula_gerrit-rest-api
Description: …
“Save”
Optional installation steps
Optionally you can fork repo tool and use your own stable version by defining “REPO_URL” and “REPO_BRANCH” in Jenkins Global Variables.
Library description
Main classes
This is only a brief description of the classes. See the specific class page for more details.
com.amarula.git.Git
Helper class for basic git operations. It can sync given tag/branch or checkout/cherry-pick Gerrit change from the given parameters.
com.amarula.gerrit.Gerrit
Helper class for basic Gerrit operations. It is used internally to query changes and set review labels in Gerrit.
com.amarula.gerrit.GerritChange
Represents single Gerrit change with enough information to fetch the change or set review labels.
com.amarula.repo.Repo
Helper class for repo managed projects. It is used to sync projects including checkout/cherry-pick of Gerrit changes or Gerrit topics.
Typical use
Repo project verification
The example below show typical use-case of repo project verification. The pipeline fetches all relevant changes with the same topic and sets a review to them.
The variable ‘env.GERRIT_TOPIC’ used in the example below is automatically set by Gerrit Trigger Plugin or can be set as Job Parameter.
Repo project test build
The next example shows another typical use-case of test build with cherry-picking some changes.
Git project test build
This example shows usage of the Git class. The example shows how to checkout a specific Gerrit change given by env.GERRIT_REFSPEC from myProject repository and checkout repository with support tools myProjectSupportTools in one line.
The GERRIT_REFSPEC is initialized by the Gerrit Trigger Plugin or can be set from Job Parameters.