Jenkins Pipeline Project(Declarative pipeline syntax, Pipeline script from SCM) - Bug Reaper

                  Bug Reaper

Lean about Automation Testing,Selenium WebDriver,RestAssured,Appium,Jenkins,JAVA,API Automation,TestNG,Maven, Rest API, SOAP API,Linux,Maven,Security Testing,Interview Questions

Sunday 22 March 2020

Jenkins Pipeline Project(Declarative pipeline syntax, Pipeline script from SCM)

We generally use "Jenkins Pipeline Project" with Large scale applications with many Jobs.

This is created by executing Jenkins file.

Jenkins file is a text file that stores the entire workflow as code.

This Jenkins file is written using Groovy DSL(Domain specific Language) based on two syntaxes, namely:

Declarative pipeline syntax

Scripted pipeline syntax 

In Jenkins create a Pipeline project





















Go to Advance Section

Now here we are creating Jenkins file, Now we will need to store this Jenkins file in Git from where the Pipeline would actually start























We write all the Jenkins File pipeline code in pipeline block

pipeline{

}


Agents: All the machines connected to Jenkins are called agents
Stages: We have multiple jobs which we need to be configured for pipeline, those jobs are called as stages

pipeline{

agent any // here we are using any because we are on local, it can vary if you have other machine //which is on linux

stages
{
stage('Build') // this is parent job
{
// include all commands or setps that your jenkins job does here
steps{
bat "mvn compile"
}
}

stage('deploy')
{
steps{
}

}

stage('test')
{
steps{
bat "mvn test"
}

}

stage('Unit Testing')
{
  steps{

}
}

stage('release')
{
steps{
echo 'releasing the project'
}
}

}

}

We should save the file with extension ".Jenkinsfile" and commit your file into Git Repository

Now after saving this we will

1.) Go to Jenkins Job
2.) In SCM section under Git mention you git Repository URL and also mention Script Path











Now notice that you have to same name of the file which you created and saved in the repo as in my case it is Jenkinsfile

Now when you trigger you job
it will execute the Pipeline and all commands you mentioned in jenkins file will be executed













No comments:

Post a Comment