Jenkins pipelines

pipelines

devops
pipelines
k8s
Author

albertprofe

Published

Tuesday, June 1, 2021

Modified

Friday, November 1, 2024

📘 What is a Jenkins

Jenkins is an self-contained & open source continuous integration/continuous delivery and deployment (CI/CD) automation software DevOps tool written in the Java programming language. Jenkins can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software

It is used to implement CI/CD workflows{.external .target=’_blank’}, called pipelines (by configuration files called Jenkinsfile or web ui).

The need for Jenkins becomes especially acute when deploying to a microservices architecture. Since one of the goals of microservices is to frequently update applications and services, the ability to do so is relevant and significant.

1 Install

Jenkins can be installed through native system packages, Docker, or even run standalone by any machine with a Java Runtime Environment (JRE) installed. Jenkins is a highly extensible product whose functionality can be extended through the installation of plugins.

Jenkins is typically run as a standalone application in its own process.

The Jenkins WAR file bundles Winstone, a Jetty servlet container wrapper, and can be started on any operating system or platform with a version of Java supported by Jenkins.

Theoretically, Jenkins can also be run as a servlet in a traditional servlet container like Apache Tomcat or WildFly, but in practice this is largely untested and there are many caveats. In particular, support for WebSocket agents is only implemented for the Jetty servlet container.

1.1 Debian Ubuntu

Prerequisites

Minimum hardware requirements:

  • 256 MB of RAM
  • 1 GB of drive space (although 10 GB is a recommended minimum if running Jenkins as a Docker container)

Recommended hardware configuration for a small team:

  • 4 GB+ of RAM
  • 50 GB+ of drive space

Software requirements:

On Debian and Debian-based[.external target=’_blank’] distributions like Ubuntu you can install Jenkins through apt.

App.bash
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins

2 Pipelines

Jenkins pipelines can be defined using a text file called JenkinsFile.

You can implement pipeline as code using JenkinsFile, and this can be defined by using a domain specific language (DSL).

With JenkinsFile, you can write the steps needed for running a Jenkins pipeline in Groovy: a (declarative and/or scripting) multi-faceted language for the Java platform very similar to yaml (declarative o more declarative).

Note

A continuous delivery (CD) pipeline is an automated expression of your process for getting software from version control right through to your users and customers.

Every change to your software (committed in source control) goes through a complex process on its way to being released. This process involves building the software in a reliable and repeatable manner, as well as progressing the built software (called a build) through multiple stages of testing and deployment.

Creating a Jenkinsfile and committing it to source control provides a number of immediate benefits:

  • 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.

2.1 Declarative Pipeline fundamentals

In Declarative Pipeline syntax, the pipeline block defines all the work done throughout your entire Pipeline.

Jenkinsfile (Declarative Pipeline)

Jenkinsfile (Declarative Pipeline)
  1. Execute this Pipeline or any of its stages, on any available agent.
  2. Defines the Build stage.
  3. Perform some steps related to the Build stage.
  4. Defines the Test stage.
  5. Perform some steps related to the Test stage.
  6. Defines the Deploy stage.
  7. Perform some steps related to the Deploy stage.

2.2 Creating your first Pipeline

  1. Install the Docker Pipeline plugin through the Manage Jenkins > Plugins page
  2. After installing the plugin, restart Jenkins so that the plugin is ready to use
  3. Copy one of the examples into your repository and name it Jenkinsfile
  4. Click the New Item menu within Jenkins

Click the New Item menu within Jenkins

Click the New Item menu within Jenkins
  1. Provide a name for your new item (e.g. My-Pipeline) and select Multibranch Pipeline
  2. Click the Add Source button, choose the type of repository you want to use and fill in the details
  3. Click the Save button and watch your first Pipeline run ## On windows

3 Reference

Back to top