Please visit my website and subscribe to my youtube channel for more articles
It is used to create stages/pipeline of all the steps which are required for building the project.
How to initialize software and set path
stage(‘Terraform Init’) {
steps {
script {
def tfHome = tool name: ‘Terraform’
def anHome = tool name: ‘Ansible’
env.PATH = “${anHome}:${env.PATH}”
env.PATH = “${tfHome}:${env.PATH}”
}
sh ‘terraform — version’
sh ‘ansible — version’
}
}
How to declare variable
def my_list
pipeline {
agent any
stages {
stage(‘stage1’) {
steps {
script {
my_list = “nidhi”
}
}
}
stage(‘stage2’) {
steps {
echo “$my_list”
}
}
}
}
Second Example
def test=”nik”
pipeline {
agent any
stages {
stage(‘stage2’) {
steps {
echo “$test”
}
}
}
}
Example of pipeline which will use variables/checkout/dockerpush