Create your Jenkins Pipeline Job
Tags: jenkins, devops, tutorial
Published: 2023-03-28 20:01:21

> ## Creating your first Jenkins pipeline.

**Step 1**: Log into Jenkins and select ‘**New item**’ from the dashboard.

![Log into Jenkins](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8lqbzh9yq15phjweyzus.png)

**Step 2**: Next, enter a name for your pipeline and select ‘pipeline’ project. Click on ‘ok’ to proceed.


![enter a name for your pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xif92zkjhlw5qksukkfy.png)

**Step 3**: Scroll down to the pipeline and choose if you want a declarative pipeline or a scripted one.


![choose if you want a declarative pipeline or a scripted one](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1sry4rw4rcmdv29zne0.png)

**Step 4a**: If you want a scripted pipeline then choose ‘pipeline script’ and start typing your code.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0sax8o1z5srjq2ttnt2u.png)

**Step 4b**: If you want a declarative pipeline then select ‘pipeline script from SCM’ and choose your SCM. In my case, I’m going to use Git throughout this demo. Enter your repository URL.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y4g2oj9es4611d468hf8.png)

**Step 5**: Within the script path is the name of the Jenkinsfile that is going to be accessed from your SCM to run. Finally, click on ‘apply’ and ‘save’. You have successfully created your first Jenkins pipeline.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6lkdvsf39xl5nq3xly5q.png)

> ## Scripted Pipeline Vs Declarative Pipeline 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xlaa8idu975eh6nl85y7.png)





> ## Declarative Pipeline Demo

The first part of the demo shows the working of a declarative pipeline. 

Refer the above ‘Creating your first Jenkins pipeline’ to start.

Let me start the demo by explaining the code I’ve written in my Jenkinsfile.

Since this is a declarative pipeline, I’m writing the code locally in a file named ‘Jenkinsfile’ and then pushing this file into my global git repository.

While executing the ‘Declarative pipeline’ demo, this file will be accessed from my git repository. 

The following is a simple demonstration of building a pipeline to run multiple stages, each performing a specific task.

> ## Required Fields of Jenkinsfile

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fm6tl4wtlur548lhj3bz.png) 

> ## Jenkinsfile code


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4up3e55fp73ojztjcqc3.png)

```
pipeline {
  
   agent any
  
   stages {
     
     stage("build") {
       
       steps {
           echo 'building the application...'
       }
     }
     stage("test") {
       
       steps {
          echo 'testing the application...'
       }
     }
     stage("deploy") {
       
       steps {
          echo 'deploying the application...'
       }
     }
  }
}

```

**push this Jenkinsfile into global git repository**

> ## Output

Click on "**Build Now**"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6rvlkp9vx7jtmhixwv7i.png)

I hope this blog helped you understand the basics of scripted and declarative pipeline and you able to perform declarative pipeline demo !