Complete the code to define a Jenkins pipeline that triggers on every code commit.
pipeline {
agent any
triggers {
[1]()
}
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
}The pollSCM trigger tells Jenkins to check the source code repository for changes regularly, enabling continuous integration by building on every commit.
Complete the Jenkins pipeline stage to run tests after building the code.
stage('Test') { steps { sh '[1]' } }
The command npm test runs the test scripts defined in the project, which is essential in continuous integration to verify code correctness after building.
Fix the error in the Jenkinsfile snippet to archive test results correctly.
post {
always {
[1] artifacts: 'test-results/*.xml', allowEmptyArchive: true
}
}The correct Jenkins pipeline step to save build artifacts is archiveArtifacts. This archives files like test reports for later review.
Fill both blanks to define environment variables and use them in the build stage.
pipeline {
agent any
environment {
APP_NAME = '[1]'
}
stages {
stage('Build') {
steps {
echo "Building $[2]"
}
}
}
}Setting APP_NAME to 'MyApp' defines the variable. Using APP_NAME inside echo prints the app name dynamically during build.
Fill all three blanks to create a post-build action that sends notifications on failure.
post {
failure {
[1] {
subject: '[2] Build Failed',
body: 'Please check the [3] logs for details.'
}
}
}The emailext step sends emails. The subject uses 'Jenkins' as the sender or system name. The body refers to 'build' logs to guide the user.