Jenkins piple
Jenkins piple
Jenkins piple
The declarative syntax is a new feature that used code for the pipeline. It provides a
limited pre-defined structure. Thereby, it offers an easy & simple continuous delivery
pipeline
Scripted Pipeline Syntax
Unlike declarative syntax, the scripted pipeline syntax is the old traditional way to write
the Jenkins file on Jenkins’s web UI. Moreover, it strictly follows the groovy syntax and
helps to develop a complex pipeline as code.
Key constructs of Jenkins file
Example: creating an application, testing it, and deploying the same. Moreover, it is a
critical element in declarative pipeline syntax, which is a collection of all stages in a
Jenkins file. We declare different stages and steps in this block.
Stage – A stage consists of a set of processes that the Pipeline executes. Additionally,
the tasks are divided in each stage, implying that there can be multiple stages within a
Pipeline. The below snippet shows the different stages that one can define in a Pipeline.
Steps – A step in Jenkins defines what we have to do at a particular step in the process.
There can be a series of steps within the stage. Moreover, whatever step we define in a
stage would be executed within it.
Agent – An agent is a directive that enables the users to execute multiple projects within the same
Jenkins instance by distributing the load. Moreover, we assign an executor to the build through an
agent. You can either use a single agent for the entire pipeline or use a distinct agent for the different
stages of the pipeline. Subsequently, some of the parameters used with agents are –
None– It is used at the pipeline root and implies no global agent, but each stage must specify its own
agent.
Label– The labeled agent is used to execute the pipeline or the specific stage.
Docker– One can use the Docker images as the execution environment & specifying the agent as
docker.
Scripted Jenkins Pipeline:
Once you have started Jenkins and logged on to its UI, you may follow the below steps to
create your first pipeline-
After that, go to the Pipeline tab, and from the Definition, the dropdown selects the Pipeline
script.
The next step is to write your pipeline code in the web UI provided by Jenkins. Let
us see a sample pipeline example as available in Jenkins-
After that, click on Save. Conclusively, this finishes the process
To create a declarative pipeline, you need to have a Jenkinsfile in place. Since I will be using
the project from my Github account, I have already placed the Jenkinsfile in my project.
For creating a Declarative Pipeline, you may follow step#1 and Step#2 from the scripted
pipeline creation steps stated above and then follow the below steps-
1. Go to the Pipeline tab, and from the Definition, the dropdown selects the Pipeline
script from SCM.
2. You need to select Git from the SCM dropdown now.
3. Now, you will get an option to input your Repository URL and credentials.
4. Next, you may set the branch or let it be blank for any branch. In the script path, you
need to write the Jenkins file name that exists in your repository. Click on Save, and
there you go, your declarative pipeline is ready for use.
Now that you are all set with your pipelines, you can execute the same from your
Jenkins UI. All you need to do is select your pipeline and click on Build Now link on the
left panel.