Complete the code to add a testing stage in a Jenkins pipeline.
pipeline {
agent any
stages {
stage('Test') {
steps {
[1] 'run tests'
}
}
}
}input instead of sh to run tests.The sh step runs shell commands, which is used here to run tests in the pipeline.
Complete the code to fail the pipeline if tests fail.
pipeline {
agent any
stages {
stage('Test') {
steps {
[1] 'exit 1'
}
}
}
}echo which only prints text and does not fail the build.The sh step runs shell commands. Using exit 1 causes the step to fail, which fails the pipeline.
Fix the error in the pipeline to properly run tests and fail on errors.
pipeline {
agent any
stages {
stage('Test') {
steps {
[1] 'pytest || exit 1'
}
}
}
}input which pauses the pipeline instead of running commands.The sh step runs shell commands. Using pytest || exit 1 runs tests and fails the pipeline if tests fail.
Fill both blanks to add a test stage that runs tests and archives results.
pipeline {
agent any
stages {
stage('Test') {
steps {
[1] 'run_tests.sh'
[2] artifacts: 'test-results/*.xml', fingerprint: true
}
}
}
}input instead of sh to run tests.The sh step runs the test script. The archiveArtifacts step saves test result files for later review.
Fill all three blanks to create a pipeline that checks out code, runs tests, and archives results.
pipeline {
agent any
stages {
stage('Build and Test') {
steps {
[1] scm
[2] './run_tests.sh'
[3] artifacts: 'results/*.xml', fingerprint: true
}
}
}
}input which pauses the pipeline instead of running commands.checkout gets the code from source control, sh runs the test script, and archiveArtifacts saves the test results.