Jenkins

Jenkins If Statement

In Jenkins, there are two ways to define the Pipeline.

1. Scripted pipeline 2. Declarative pipeline

The if-else statement in Jenkins’s declarative and scripted Pipeline.

Jenkins scripted pipeline if else statement

To create a new pipeline in Jenkins Goto, the Jenkins UI and click on New item. Give the pipeline name as Jenkins pipeline-if statement, select Pipeline, and click the ok button.

Jenkins Declarative pipeline if else statement

We can define the if-else statement in Jenkins’s declarative Pipeline.

Declarative Pipeline explanation

The Declarative pipeline should start with the mandatory pipeline block.

1. Pipeline

Agent signifies where the Jenkins build job should run. In this case, we have selected agent as any

2. Agent

stages block consists of different executable stage blocks. – At least one stage block is mandatory inside stages block.

3. Stages/stage

Steps blocks consists of the actual operation which needs to be performed inside jenkins.

4. Steps

- In the script session we can define scripted pipeline codes. - In many use-cases, the script step is unnecessary in Declarative Pipelines, but it can provide a useful “escape hatch.”

5. Script