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 :
- 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.
- 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.
- stages: Different stages can be there such as dev, test, build, deploy, etc. Logical phases of the pipeline that group related steps together.
- steps: This block contains the steps to be executed in the stages.
Example of a single-stage pipeline :
pipeline {
agent anystages {
stage('Test') {
steps {
echo "Understanding single-stage pipeline"
}
}
}
}
Example of a multi-stage pipeline :
pipeline {
agent anystages {
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.
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.
pipeline{
agent{docker
{image'golang:latest'}
stages{stage('development')
{steps
{
git"https://github.com/AdminTurnedDevops/go-webapp-sample"
sh 'go version'
}}
}
}