Continuous integration/Tutorials/Adding basic checks

This tutorial shows up how to add a very basic check in Jenkins, we will base this tutorial on operations/dns.git which hold Wikimedia DNS configuration. The aim is to validate the syntax of the DNS zone files.

What we want to achieve:

Whenever a patch is send against operations/dns.git we want to expand the gdnsd templates and have it validate the syntax. When no error is detected, Jenkins should vote Verified +2 to let people merge the change after review, if something is wrong, we would vote Verified -1 to let people know the syntax is invalid.

Prerequisites
- gdnsd installed on all production Jenkins slaves. This is achieved in puppet is out of the scope of this tutorial - a local installation of Jenkins Job Builder, you want to read our step by step guide to install Jenkins Job Builder

Editing Jenkins configuration
The miscellaneous operations/ repositories are configured inside operations-misc.yaml. We will need to create a new Jenkins project that gives the Gerrit repository name and list the jobs we want to attach to it.

The gerrit-name is a variable that will be passed to job templates and in turns let Jenkins know which repository to fetch the submitted patchset from.

Now lets create our job template. It needs: - a name so we can reference it in the project definition - a few default parameters which let the job be triggered by Zuul - we then add the shell commands we want to execute:

Now we want to edit the project definition to reference this template.

The name and gerrit-name values are passed to the job-template. Jenkins Jobs Builder use them to expand the default parameters we have applied inside the job template (i.e. defaults: use-zuul).

Now have Jenkins Job Builder to generate the configuration using jenkins-jobs test -o - config/ operations-dns-lint</tt>. It will parse the YAML definition, realize the operations-dns-lint</tt> job and write out on standard output the XML Jenkins job definition. If something went wrong, you want to double check your YAML definition, usually the errors are related to a wrong indentation (use two spaces for indentation).

The command is:

$ jenkins-jobs --conf jenkins_jobs.ini test -o - config/ operations-dns-lint // snip XML output

The most important things to check are: - the git repository name - the builders section (the actual commands that would be run).

The git configuration is

The repository URL is /srv/ssd/zuul/git/operations/dns</tt> which trailling part is the gerrit project. If you see {gerrit-name}</tt> there is an issue in your configuration. The refspec $ZUUL_REF and branch specifier $ZUUL_COMMIT are provided by Zuul and let the Jenkins git plugin to fetch the patchset.

Then verify the shell commands you want to execute under the builders</tt> section. Note that some characters needs to be escaped (such as double quotes) since it is an XML file:

Once happy, you can deploy the configuration on Jenkins:

$ jenkins-jobs --conf jenkins_jobs.ini update config/ operations-dns-lint

If all went well, the job should be available at https://integration.wikimedia.org/ci/job/operations-dns-lint/ :



When clicking the configure link, you can review the final configuration. Browsing down at the bottom of that page you will see the actual shell commands that would be run: