CI/CD as Code Part IV - Stateless Jenkins : Jobs as Code - Advanced

Image
In the previous article of these examples , we created a stateless jenkins container which can be initialised solely by using scripts. In that example, a seed job for jobdsl plugin was also implemented. This job was later on used to create an automated simple jenkins job inline. In order to create more complex jobs in an automated fashion, we will extend previous seed job implementation further in this example. Our extended seedJob will poll a job definition repository to gather the information on how to create new complex jobs for some other remote repositories.

CI/CD as Code Part I - Introduce a stateful containerised Jenkins

The purpose of these sample series is to create a simple set of examples, which showcases CI/CD as Code, using Jenkins. Primary goal is to create a stateless CI/CD setup, which can be bootstrapped from a set of configuration files and scripts so that many problems related to maintenance of the infrastructure and other operational issues are reduced.
A step by step approach is followed while implementing the examples. The documentation regarding each step can be reached using the links below.

Sample Steps

  1. Introduce a stateful containerised Jenkins
  2. Complete the basic setup of Jenkins via code: The goal of this step is to complete basic setup of Jenkins completely programmatically.
  3. First steps to 'job as code' : In this step, we are going to head towards configuring jobs programmatically.
  4. Stateless Jenkins - Job as Code Part II: In this part we are going to finalise setup and define some example jobs.

Introduce a statefully containerised Jenkins

Checkout this sample from here.
This initial form tackles only with a containerised version of Jenkins. The goal is to head towards a stateless form of a jenkins setup. In this initial version, we will only have a dockerized Jenkins instance, the state of which will be mapped to static folders in the host machine.

The advantage of this setup is to have the state, which includes history, configurations, etc, preserved in the host machine and it's not that different from having Jenkins installed on a physical/virtual machine. You still need to setup the installation via Jenkins initial setup interface and configure your jobs, pipelines etc manually. Nevertheless, it's the initial step towards the "... as a code" approach.

Container Configuration


Port mappings:
  • Jenkins' default http port 8080 is mapped to 7080 on the host machine.
  • Jenkins' default jnlp port 50000 is mapped to 50005 on the host machine.

Checkout docker-compose.yml for additional configuration.

How to run the sample

  • Go to ci_cd root directory and run docker-compose up.
    jenkins_home directory is mapped to the directory ./jenkins/jenkins_home on the host machine. As soon as your container gets up-and-running, you will be able to see jenkins related files in this directory. For such kind of setups Jenkins creates a temporary admin password in the file jenkins/jenkins_home/secrets/initialAdminPassword.

  • Navivgate to http://localhost:7080 and use the temporary password defined in jenkins/jenkins_home/secrets/initialAdminPassword to start configuring your Jenkins instance.
  • Follow the steps defined in the setup interface of Jenkins.

Comments

Popular posts from this blog

CI/CD as Code Part IV - Stateless Jenkins : Jobs as Code - Advanced

Generating Rest API Documentation Using Rest Assured Tests in a Spring Boot Based Application

Testing Java Projects with Groovy