Complete the code to run a stage only when changes are detected in the 'src/' directory.
stage('Build') { when { changeset '[1]' } steps { echo 'Building project...' } }
The changeset 'src/**' condition runs the stage only if files under 'src/' changed, keeping the pipeline fast by skipping unnecessary builds.
Complete the code to cache dependencies in a Jenkins pipeline using the 'stash' step.
stage('Cache Dependencies') { steps { [1] name: 'deps', includes: 'node_modules/**' } }
The stash step saves files temporarily to speed up later stages by reusing dependencies.
Fix the error in the pipeline code to parallelize tests correctly.
parallel {
unit: {
steps {
sh 'run-unit-tests.sh'
}
},
integration: {
steps {
[1] 'run-integration-tests.sh'
}
}
}The sh step runs shell commands in Linux agents. Using it correctly runs the integration tests in parallel.
Fill both blanks to enable polling for changes and ensure the source code is checked out.
pipeline {
agent any
triggers {
pollSCM('[1]')
}
options {
skipDefaultCheckout [2]
}
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
}Setting pollSCM('H/5 * * * *') enables polling for changes, and skipDefaultCheckout false ensures the source code is checked out, which is needed for builds.
Fill all three blanks to define a fast pipeline that runs tests in parallel and uses caching.
pipeline {
agent any
stages {
stage('Prepare') {
steps {
[1] name: 'cache', includes: 'dependencies/**'
}
}
stage('Test') {
parallel {
unit: {
steps {
[2] 'run-unit-tests.sh'
}
},
integration: {
steps {
[3] 'run-integration-tests.sh'
}
}
}
}
}
}Use stash to cache dependencies, and sh to run shell scripts for both unit and integration tests in parallel, keeping the pipeline fast.