Complete the code to start a Jenkins pipeline with a simple stage.
pipeline {
agent any
stages {
stage('Build') {
steps {
[1] 'echo Building...'
}
}
}
}The sh step runs shell commands in Jenkins pipelines. It is used here to print a message.
Complete the code to trigger a Jenkins job automatically after a code push.
pipeline {
triggers {
[1] 'H/5 * * * *'
}
stages {
stage('Test') {
steps {
sh 'echo Testing...'
}
}
}
}pollSCM tells Jenkins to check the source code repository regularly for changes and trigger the job if changes are found.
Fix the error in the Jenkins pipeline code to archive build artifacts.
pipeline {
agent any
stages {
stage('Archive') {
steps {
archiveArtifacts artifacts: '[1]'
}
}
}
}The pattern '**/*.jar' archives all jar files in any folder, which is common for build artifacts.
Fill both blanks to define environment variables and use them in a Jenkins pipeline.
pipeline {
agent any
environment {
GREETING = [1]
}
stages {
stage('Say Hello') {
steps {
sh 'echo [2]'
}
}
}
}Environment variables are set with a string value like 'Hello, Jenkins!' and accessed in shell steps with $GREETING.
Fill all three blanks to create a Jenkins pipeline that builds, tests, and deploys with proper stages.
pipeline {
agent any
stages {
stage('Build') {
steps {
sh '[1]'
}
}
stage('Test') {
steps {
sh '[2]'
}
}
stage('Deploy') {
steps {
sh '[3]'
}
}
}
}The typical pipeline runs make build to compile, make test to run tests, and make deploy to deploy the app.