Complete the code to define a Jenkins pipeline stage named 'Build'.
stage('[1]') { steps { echo 'Building the project' } }
The stage name should be 'Build' to represent the build step in the pipeline.
Complete the code to trigger the pipeline only when changes are pushed to the 'main' branch.
pipeline {
agent any
triggers {
[1] {
pollSCM('H/5 * * * *')
}
}
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
}The 'pollSCM' trigger checks the source code management for changes, and can be configured to watch the 'main' branch.
Fix the error in the Jenkinsfile snippet to correctly checkout code from Git.
pipeline {
agent any
stages {
stage('Checkout') {
steps {
[1]([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/example/repo.git']]])
}
}
}
}The correct Jenkins pipeline step to checkout code is 'checkout'.
Fill both blanks to create a post-build action that always sends an email notification.
post {
[1] {
mail to: 'team@example.com', subject: 'Build [2]', body: 'The build has finished.'
}
}The 'always' block runs after every build, and the subject uses 'always' to indicate the build status.
Fill all three blanks to define an environment variable and use it in a shell step.
pipeline {
agent any
environment {
[1] = '[2]'
}
stages {
stage('Print Env') {
steps {
sh 'echo [3]'
}
}
}
}Define environment variable 'MY_VAR' with value 'HelloWorld' and use it in shell with '$MY_VAR'.