Complete the code to run unit tests using the 'sh' step in Jenkins pipeline.
pipeline {
agent any
stages {
stage('Test') {
steps {
[1] 'pytest'
}
}
}
}The sh step runs shell commands in Jenkins pipeline. Here, it runs pytest to execute unit tests.
Complete the code to define a Jenkins pipeline stage named 'Unit Tests'.
stage('[1]') { steps { sh 'pytest' } }
The stage name should describe the step. Here, 'Unit Tests' clearly indicates running unit tests.
Fix the error in the Jenkins pipeline step to run tests with Python 3.
steps {
sh '[1] -m pytest'
}Using python3 ensures the tests run with Python 3 interpreter.
Fill both blanks to run tests only if the branch is 'main'.
when {
[1] '[2]'
}The when condition with branch 'main' runs the stage only on the 'main' branch.
Fill all three blanks to save test results as JUnit reports in Jenkins.
post {
always {
junit '[1]/[2].xml'
archiveArtifacts artifacts: '[3]/*.xml', allowEmptyArchive: true
}
}JUnit reports are saved in 'test-results' folder with XML files. Archiving the same folder keeps test reports in Jenkins.