Mastering CI/CD: A Comprehensive Guide to Building Your First Jenkins Pipeline | by Naman Sharma

It is a text file consisting of definitions such as instructions and templates. It tells the pipelines what they should be doing, and what service or plugin they should interact with. Things that a Jenkins file consists of are :

  1. pipeline: it includes whether you want to build the code, run it, or deploy it.Defines the overall process and stages of the build. It specifies what actions should be performed, such as building, testing, and deploying code.
  2. Build agent: Build agents is the environment where your code runs. Build agents, or nodes, execute the defined steps in the pipeline. They can be on different machines or containers, depending on your configuration.
  3. stages: Different stages can be there such as dev, test, build, deploy, etc. Logical phases of the pipeline that group related steps together.
  4. steps: This block contains the steps to be executed in the stages.

Example of a single-stage pipeline :

pipeline {
agent any

stages {
stage('Test') {
steps {
echo "Understanding single-stage pipeline"
}
}
}
}

Example of a multi-stage pipeline :

pipeline {
agent any

stages {
stage('Test') {
steps {
echo "Understanding single-stage pipeline"
}
stage('Dev'){
steps {
echo " Understanding multi-stage pipeline"
}
}
}
}

Let us now create a pipeline in Jenkins :

Step 1: Go to Jenkins Dashboard and create a new item.

Choose the Pipeline option.
Choose or select the options if they are required.
save and build.
Successfully build. Press build one time only otherwise it will build it again.

Let us now create a pipeline using Container as a build agent :

All the steps are the same as mentioned above, we just need to change the script.

Save and build.
pipeline{
agent{docker
{image'golang:latest'}
stages{stage('development')
{steps
{
git"https://github.com/AdminTurnedDevops/go-webapp-sample"
sh 'go version'
}

}

}
}

Thank you for reading……..

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *