Complete the code to define a Jenkins pipeline that starts with the 'Build' stage.
pipeline {
agent any
stages {
stage('Build') {
steps {
[1] 'echo Building the project'
}
}
}
}The sh step runs shell commands in Jenkins pipelines. Here, it runs the echo command in the Build stage.
Complete the code to add a 'Test' stage after the 'Build' stage in the Jenkins pipeline.
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'echo Building the project'
}
}
stage('[1]') {
steps {
sh 'echo Running tests'
}
}
}
}The stage name should be 'Test' to represent the testing phase in the pipeline.
Fix the error in the Jenkins pipeline code by completing the missing keyword for parallel stages.
pipeline {
agent any
stages {
stage('Build and Test') {
[1] {
stage('Build') {
steps {
sh 'echo Building'
}
}
stage('Test') {
steps {
sh 'echo Testing'
}
}
}
}
}
}The parallel block allows running multiple stages at the same time in Jenkins pipelines.
Fill both blanks to create a Jenkins pipeline stage that runs only when the branch is 'main'.
pipeline {
agent any
stages {
stage('Deploy') {
when {
[1] '[2]'
}
steps {
sh 'echo Deploying to production'
}
}
}
}The when block with branch 'main' ensures the Deploy stage runs only on the main branch.
Fill all three blanks to create a Jenkins pipeline that defines an environment variable and uses it in a shell command.
pipeline {
agent any
environment {
[1] = '[2]'
}
stages {
stage('Print Env') {
steps {
sh 'echo [3]'
}
}
}
}The environment variable GREETING is set to 'Hello, World!'. The shell command uses $GREETING to print its value.