Complete the code to define a Jenkins pipeline that runs on any available agent.
pipeline {
agent [1]
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
}The agent any directive tells Jenkins to run the pipeline on any available agent.
Complete the code to trigger a Jenkins pipeline using periodic SCM polling.
pipeline {
agent any
triggers {
pollSCM('[1]')
}
stages {
stage('Test') {
steps {
echo 'Testing...'
}
}
}
}The pollSCM('H/5 * * * *') trigger tells Jenkins to poll the SCM every 5 minutes (H distributes load across agents).
Fix the error in the Jenkins pipeline syntax to correctly define environment variables.
pipeline {
agent any
environment {
PATH = '[1]'
}
stages {
stage('Deploy') {
steps {
echo "Deploying with PATH: $PATH"
}
}
}
}Environment variables in Jenkins pipelines are set as key-value pairs without spaces around the equals sign. To prepend to PATH, use /usr/local/bin:$PATH.
Fill both blanks to create a Jenkins pipeline stage that runs a shell command and archives the artifacts.
stage('Build') { steps { sh '[1]' archiveArtifacts '[2]' } }
The sh step runs the shell command make build. The archiveArtifacts step saves the build output matching **/target/*.jar.
Fill all three blanks to define a Jenkins pipeline that checks out code, runs tests, and sends a notification.
pipeline {
agent any
stages {
stage('Checkout') {
steps {
[1] 'https://github.com/example/repo.git'
}
}
stage('Test') {
steps {
sh '[2]'
}
}
stage('Notify') {
steps {
[3] 'Build completed successfully'
}
}
}
}The git step clones the repository. The sh step runs tests with make test. The echo step sends a simple notification message.