First look on Jenkins pipelines with a simple Lazarus application
Hi!
We all know cool CI server called Jenkins. They have started a new project: Blue Ocean with new UI and based on Jenkins pipelines. Today I’ll set up a simple pipeline for a one-button Lazarus application.
Let’s go!
First of all, you need to set up a git repository (svn is currently not supported by Blue Ocean, because of the unstable svn plugin). I have used this one. Then install Jenkins, use the official installer from their website (link). But I personally prefer other type of installation: installation using Docker. There is only one thing you need to do:
docker pull jenkinsci/blueocean
Installation of Jenkins is fairly simple and I’ll not describe it here. You just need to run an installer, find an admin password, install some plugins and define a first user.
Install Blue Ocean
Blue Ocean is actually a set of plugins for Jenkins that include new UI and new functions. You should install it:
After restart of Jenkins you’ll see a button on the left sidebar. Click on it!
Working with Blue Ocean
You’re in the Blue Ocean window now. Create a new pipeline!
Select your git repository and add an access key (or credentials). Now you’re ready for creating a first pipeline. Then you can create a first stage. In my case, it’s “checkout”
This stage has one step: Git.
Click on “Save” to save your pipeline. At this point, your repository should have a Jenkinsfile that describes your build process:
With this file you can build your project on every Jenkins instance, without nearly any preconfiguration! Now it’s time to add a build script to this pipeline. I said that we will build a small one-button-app. Here is our build script:
lazbuild onebutton.lpi
Yes, very simple. “lazbuild” is a tool that can compile Lazarus project outside of the IDE. Time to add a new stage with a new step!
Note: if you have changed PATH variable, you should restart Jenkins.
And then commit a new version of Jenkinsfile! And now we see this:
Our application was built successfully! What I also like about new Blue Ocean that we can not only use this visual editor, but also edit Jenkinsfile manually. Look at this:
You see that the whole “boilerplate” code was generated by Jenkins. Now you can just add new steps. It’s very simple. Find a “bat” step here :)
FPCUnit
A very interesting question for me was whether it’s possible to integrate FPCUnit into Jenkins. Time to write a test!
Using Blue Ocean I got the following Jenkinsfile:
As you can see, here I build and run tests, but I can’t collect results. We need to go down to Jenkins to add this. We need to go deeper.
First of all, we need to install a xUnit plugin that can consume .xml reports from FPCUnit:
But there is a problem that I had to solve: FPCUnit generates UTF16 files with UTF8 encoding in header:
But I found a workaround: I convert a FPCUnit report to UTF8 with a powershell script:
If you’ll look into my Jenkinsfile then you’ll see that I use xUnit with a following code:
But I didn’t write it by myself! You need to generate a snippet and insert it into a Jenkinsfile:
This window helps you to generate a hard snippet :) It’s cool! Here you can set how many tests need to be failed to fail whole build. I set it to 0 and changed my test:
My build fails:
As you can see, it’s possible to use FPCUnit with Jenkins, but it’s not very straightforward. I think that I forgot to describe something, so try to build my demo for this blog post: https://github.com/Zawuza/pipeline-lazarus-demo
What else?
Topic of CI systems is pretty large and my article is just a starting point for you. If you are using Lazarus, it can be cool if you integrate a website of your product with Jenkins so that visitors of your website can always download a newest version of your application. You can add a hook so that Jenkins will build your application after each commit automatically. So, you can use all benefits of CI :)
That’s all for today!