Press "Enter" to skip to content

Author: Eduardo Lezcano

Engineer, developer and creator

Simply curious

Validating Jenkinsfile

I had many problems with Jenkinsfiles lately. The syntax is so picky that after a push my plan fails just because I forgot a comma or something as ridiculous as that. In my opinion there are better human input methods for such a file, like yaml. But hey! I’m not developing Jenkins.

Anyway I just integrated a target into my project makefile to test the validity of the Jenkins file. The only way in this case is to send it to your Jenkins server in order to test it like so:

test: jenkins.validate
jenkins.validate:
    @curl -X POST -F "jenkinsfile=<Jenkinsfile" \
      http://localhost:8080/pipeline-model-converter/validate
    @echo "Jenkinsfile tested."

Is super nice to use the REST API to validate your files but still this has some problems to consider: security (posting to http) or weight of the solution (you need to have a complete Jenkins server in your local host). But that’s not in the scope of this entry.

Chef and Docker for a rapid infrastructure development

We started using Chef a while ago and one of the first steps we took was to use Docker instead of Vagrant for performing tests due to it’s faster setup.
After all this time I can say it was a nice experience and now our CI is happily testing our in minutes. So…

What do you need?

Basically you need to install the latest ChefDK where the gem kitchen-dokken is installed by default. This gem enables a light-weight tooling to use Docker containers for executing Kitchen.

Setup

After that you just need to setup your kitchen.yml to use dokken as driver like so:

---
driver:
  name: dokken
  chef_version: latest

transport:
  name: dokken

provisioner:
name: dokken

...

The transport and the provisioner are set to dokken so kitchen will use the lighter tooling from the driver. Then you can setup your platform to test your cookbooks:

  - name: ubuntu-16.04
    driver:
      image: ubuntu:16.04
      pid_one_command: /bin/systemd
      intermediate_instructions:
        - RUN /usr/bin/apt-get update

Considerations

  • Docker is designed for isolating and packaging processes that runs as the only process inside a container.
    If your cookbook setup services you may need to choose a complete Docker base image that normally is bigger in size, also you need to explicitly start the system daemon (such as systemd) like you saw on the code snippet earlyer.

  • Do not try to run Docker inside a container. If your cookbook uses Docker somehow is better to use Vagrant instead because then you may need to manually setup the container to host docker and that is a pain.

Tribute to regex

Today I was working with Regular Expressions and suddenly come into my mind the question:

How such a great invention as Regex was created?

I rapidly checked it and I get to the wikipedia page. I had no idea about who created such a good idea. Stephen Kleen owe our admiration, he was a complete person who, in my opinion, has helped the humanity to advance. Thanks man!

Stephen Cole Kleene, creator of the regular expressions

I want youngsters like me to change the way they see what they are working with. They are so focused on their own cutting-edge projects that looking back seems like a waste of time. But is not.