Continuous Integration on Openshift via Jenkins

In previous articles, several deployment methods were shown. This time is quite a bit different from the others. The goal of the article is information about continuous integration. To achieve this, openshift and Jenkins will be used.

Before the beginning, There are some concepts that help to understand better. These are Jenkins, Jenkins pipeline and continuous integration (CI). The concepts will be explained as follows.

What is Jenkins ?

Jenkins is an open source automation server. Jenkins is an integration tool developed with java. helping automate parts of the software development process is the other definition of Jenkins. Jenkins software enables developers to quickly find defects in a code base, solve them, and automate tests.

The Openshift Container Platform provides a container image for running Jenkins. This image provides a Jenkins server instance, which can be used to set up a basic flow for continuous testing, integration and delivery.

What is ContinuousIntegratıon ?

Continuous Integration is a process where all development works are integrated. The resulting artifacts are automatically generated and tested. This process helps to define errors as early as possible.

What is Jenkins Pipeline ?

Jenkins pipeline is a set of plugins which helps to implement and integrate continuous delivery pipelines into jenkins. The definition of a Jenkins Pipeline is written into a text file.

Creating a Jenkinsfile and committing it to source control provides :

  • Automatically creates a Pipeline build process for all branches and pull requests.
  • Code review/iteration on the Pipeline (along with the remaining source code).
  • Audit trail for the Pipeline.
  • Single source of truth for the Pipeline, which can be viewed and edited by multiple members of the project.

Continuous Deployment Example

After the information part, here is the example part. First open openshift web console. Then click jenkins image in that console.

Openshift Web Console

Click next, then set up the preferences and click close after that.

Openshift Web Console

Open the project. There will be a route. Wait for deployment process after that, click the route. Jenkins will be up and ready.

Openshift Web Console
Openshift Web Console

Click the button. After that, Authorize Access page will open. Click allow button.

Openshift Web Console

Finally, jenkins page opens.

Openshift Web Console

In this page, chose new item.

Openshift Web Console

Give name the item and choose the pipeline section.Then click ok button.

Openshift Web Console

When this page opens, do not change anything at the top of the page. Just write a Jenkinsfile script. That script pulls the red hat image and also pull from github source code. After that, gives a route basically. The script will be explained piece by piece as follows.

Openshift Web Console

This pipeline statement is a relatively recent addition to jenkins pipeline, which presents a more simplified and opinionated syntax on top of the pipeline sub-system. This is a valid declaration. Pipelines must be enclosed within a pipeline block.

The agent section is used for where all pipeline or specific stage will run in the jenkins environment. This part has to be defined at the top-level in the pipeline script. Label parameter executes the pipeline on an agent or a state that available in the environment

Stages contain at least one stage directive for each discrete part of the continuous delivery process, such as Build, Test and Deploy.

The steps section defines a series of one more step to be executed in a given stage.

The script part takes a block of scripted pipeline and run in the declarative pipeline.

In try catch block, if there is an image in there, the old image is erased.

After all, click save button. On the main menu, click the schedule a build button.

Openshift Web Console

It takes time to build the code. After that, the logo of the application is turned blue if the building process is successful. If it is not, the logo is turned into red.

Now open openhift.

Openshift Web Console

As can be seen, jenkins application is added automatically. When pressing the link, the application will open.

Openshift Web Console

There is a second way to pull project from github into openshift jenkins. that is shown as follows. First part is the same until the writing script part. Now in the script part, choose Pipeline script from SCM and write the github address.

Openshift Web Console

The important part is there has to be a jenkinsfile in the project. After writing github link, press save. The rest is same before.