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 a Jenkins pipeline only when a commit is pushed to the 'main' branch.
pipeline {
agent any
triggers {
pollSCM('[1]')
}
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
}The trigger should specify a cron expression for polling SCM, such as 'H/5 * * * *'. Branch filtering is not done in pollSCM but in SCM configuration.
Fix the error in the Jenkins pipeline code to correctly define an environment variable.
pipeline {
agent any
environment {
VERSION = '[1]'
}
stages {
stage('Build') {
steps {
echo "Version is $VERSION"
}
}
}
}Environment variables in Jenkinsfile should be assigned string values with single quotes.
Fill both blanks to create a Jenkins pipeline stage that runs tests only if the build stage succeeds.
stage('Test') { when { [1] [2] 'Build' } steps { echo 'Running tests' } }
The 'when' condition uses 'stage' and 'equals' to check if the 'Build' stage succeeded.
Fill all three blanks to define a hybrid Jenkins pipeline that uses both scripted and declarative syntax.
pipeline {
agent any
stages {
stage('Hybrid') {
steps {
script {
if (env.BRANCH_NAME == '[1]') {
echo '[2]'
} else {
echo '[3]'
}
}
}
}
}
}The script checks if the branch is 'main' and echoes the appropriate message for main or feature branches.