Tuesday, April 8, 2014

Jenkins plugin for building RPMs in Copr

Imagine situation that you are continuously building your project in Jenkins, all tests are passing and you think you just fixed some annoying bug. Now it would be great to get some feedback on your fix from the guy who reported the bug or from someone else. You could point the guy to the repo, ask him to rebuild your project and test it. But it could be too much work for him. Maybe he's not a programmer or doesn't have all the necessary development/build tools installed. Even if he is a technical person, a lot of things could go wrong during the process.
I have written simple Jenkins plugin which can build RPM package for every successful Jenkins build. The name of the plugin is "copr-plugin" and as the name suggests, it delegates all the hard work to Copr. Copr handles actual building and puts the resulting RPMs into user-defined repos. It means that people can test what's in your master (or any other) branch by simply installing RPM package. Or you can, for example, enable your Copr repo in VM and have latest development version of your project installed just few minutes after you pushed your changes to the SCM.

Let's take a look on how to set all this up. First of all, you will need FAS account in order to be able to use Copr. Next you should make sure that the project you're trying to build in Copr meets some basic criteria. And that's it, no more constraints. We are now finally getting to the Jenkins plugin itself.

The plugin is not part of the default installation, so you'll need to install it first. Luckily, it is available through official Jenkins channels. Go to "Manage Jenkins->Manage Plugins->Available" and search for "copr plugin". Select the checkbox and click "Install without restart".

Now it is possible to activate the plugin from "Add post-build action" drop-down menu in your project's configuration.

Almost there, one last missing bit is configuration. You need to specify where Copr is running (API URL), your FAS username, name of your Copr repository (coprname), API login and API token. These last two are special credentials generated by Copr, you can get yours here (you must log in first with your FAS username+password).

And here comes the tricky part. You need to feed Copr with URL to SRPM. Copr currently doesn't support uploading SRPMs. However, you can write simple shell script which will create SRPM and upload it to some visible place, so Copr will be able to download it. The script can take advantage of some handy environment variables.

You may also want to wait for Copr to finish the build, but keep in mind that such waiting can block other tasks in Jenkins. If this option is enabled, then failed Copr build means also failed Jenkins job.

And that's it. Happy building.