What is Jenkins?

Nanduri Balajee
4 min readJan 8, 2020

--

Defining a Pipeline

Scripted Pipeline is written in Groovy. The relevant bits of Groovy syntax will be introduced as necessary in this document, so while an understanding of Groovy is helpful, it is not required to work with Pipeline.

A basic Pipeline can be created in either of the following ways:

• By entering a script directly in the Jenkins web UI.

• By creating a Jenkinsfile which can be checked into a project’s source control repository.

The syntax for defining a Pipeline with either approach is the same, but while Jenkins supports entering Pipeline directly into the web UI, it’s generally considered best practice to define the Pipeline in a Jenkinsfile which Jenkins will then load directly from source control.

Defining a Pipeline in the Web UI

To create a basic Pipeline in the Jenkins web UI, follow these steps:

• Click New Item on Jenkins home page.

  • Enter a name for your Pipeline, select Pipeline and click OK

Global Variable Reference

In addition to the Snippet Generator, which only surfaces steps, Pipeline also provides a built-in “Global Variable Reference.” Like the Snippet Generator, it is also dynamically populated by plugins. Unlike the Snippet Generator, however, the Global Variable Reference only contains documentation for variables provided by Pipeline or plugins, which are available for Pipelines.

Get practical explanation on this tool through DevOps Online Training

The variables provided by default in Pipeline are:

env

Environment variables were accessible from Scripted Pipeline, for example, env.PATH or env.BUILD_ID. Consult the built-in Global Variable Reference for a complete, and up to date, list of environment variables available in Pipeline.

params

Exposes all parameters defined for the Pipeline as a read-only Map, for example:

params.MY_PARAM_NAME.

currentBuild

May be used to discover information about the currently executing Pipeline, with properties such as current build.the result, current build.displayName, etc. Consult the built-in Global Variable Reference for a complete, and up to date, list of properties available on the current build.

What is Jenkins?

Jenkins Pipeline (or simply “Pipeline” with a capital “P”) is a suite of plugins which supports implementing and integrating continuous delivery pipelines into Jenkins.

A continuous delivery 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 the progression of the built software (called a “build”) through multiple stages of testing and deployment.

Typically, the definition of a Jenkins Pipeline is written into a text file (called a Jenkinsfile) which in turn is checked into a project’s source control repository. [2: Source Control Management] This is the foundation of “Pipeline-as-Code”; treating the continuous delivery pipeline a part of the application to be versioned and reviewed like any other code. Creating a Jenkinsfile provides a number of immediate benefits:

• Automatically create Pipelines for all Branches and Pull Requests

• Code review/iteration on the Pipeline

• Audit trail for the Pipeline

• Single source of truth for the Pipeline, which can be viewed and edited by multiple members of the project.

While the syntax for defining a Pipeline, either in the web UI or with a Jenkinsfile, is the same, it’s generally considered best practice to define the Pipeline in a Jenkinsfile and check that into source control.

Creating a Jenkinsfile

As discussed in the Getting Started section, a Jenkinsfile is a text file that contains the definition of a Jenkins Pipeline and is checked into source control. Consider the following Pipeline which implements a basic three-stage continuous delivery pipeline.

// Declarative //pipeline {agent anystages {stage('Build') {steps {echo 'Building..'
}
}
stage('Test')
{
steps
{
echo 'Testing..'
}
}
stage('Deploy')
{
steps {
echo 'Deploying....'
}
}
}
}// Script //
node{
stage('Build') {
echo 'Building....'
}
stage('Test') {
echo 'Building....'
}
stage('Deploy') {
echo 'Deploying....'
}
}

The Declarative Pipeline example above contains the minimum necessary structure to implement a continuous delivery pipeline. The agent directive, which is required, instructs Jenkins to allocate an executor and workspace for the Pipeline. Without an agent directive, not only is the Declarative Pipeline not valid, it would not be capable of doing any work! By default, the agent directive ensures that the source repository is checked out and made available for steps in the subsequent stages`

Get more practical knowledge at DevOps training

The stages directive and steps directives are also required for a valid Declarative Pipeline as they instruct Jenkins what to execute and in which stage it should be executed.

--

--

Nanduri Balajee
Nanduri Balajee

Written by Nanduri Balajee

Iam a Technical Content writer having 4years of Industry experience. Till now, I have written 300+ articles and 6 tutorials

No responses yet