Jenkins is a free tool that offers countless capabilities thanks to the availability of thousands of plugins, which are constantly being upgraded and released.
The most basic approach to managing tasks is the actual Jenkins web interface, where we can configure whatever we need. Unfortunately, the more tasks we have and the more varied they are, the harder it is to maintain.
Today we’ll be looking at how we can make creating tasks in Jenkins easier and faster.
This is a python script that lets us describe tasks in YAML and JSON format and then uploads them to the server via HTTP API. We just have to install it on our local machine, write the configuration file with connections, and describe the tasks.
This is a Jenkins plugin, which we can use to describe tasks in a special language (DSL, Domain Specific Language) and then generate them from those descriptions. It runs locally on the actual Jenkins server.
This is a type of Jenkins task that we can use to describe deployment or application build processes in stages. We’ll be describing our pipeline in a special Jenkinsfile, which will be saved in the project’s repository.
This is the most popular and actively developing self hosted project, which is also used by many companies. There are separate community and enterprise versions.
Gitlab has its own CI written in Go, which lets us execute various build and deploy stages from Runners.
To get started, we have to create a .gitlab-ci.yml file in the project’s repository. This is where we’ll describe our execution sequence. Docker would work excellently in this case.
To start off, we’ll install the necessary tools.
In our case, Jenkins Job Builder has be be installed on both the local machine and the machine that will run the gitlab agent (although this can be the local machine as well).
We’ll be able to test it locally to describe our seed job.
I should add that “seed job” in DSL Plugin terminology is a free-style jenkins job that creates other jobs from DSL scripts.
We’ll create a repository for our code with the task description.
Now we’ll connect gitlab-runner to our project. Since the gitlab interface has seen a lot of frequent changes recently, we recommend referencing the official documentation.
Now we’ll prepare the repository with our task description. We’ll give it the name repo-dsl and a flat structure. No files have to be moved.
We’ll configure a webhook to launch the seed-job we created earlier.
In this version of gitlab, webhooks are located in the Settings → Integrations section of the project.
In the test pipeline, we’ll build a Docker image, which will be loaded to the local Docker registry afterwards. The image file will be taken from another project.
To automatically launch this task, we can add a webhook to the project with our Docker image, where the task will be launched after changes are sent to the repository.
In conclusion, we’d like to note that this article describes just one of the many possible approaches to managing tasks in Jenkins. Thanks to its flexibility and functionality, you can use whatever approach makes managing tasks as easy and comfortable as possible for you (based on your infrastructure and requirements).