Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a Jenkins pipeline stage that runs tests.
Jenkins
stage('Test') { steps { [1] 'runTests.sh' } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' instead of 'sh' causes an error.
Using 'execute' is not a Jenkins step.
✗ Incorrect
In Jenkins pipelines, sh is used to run shell commands.
2fill in blank
mediumComplete the code to configure SCM polling with a cron schedule.
Jenkins
pipeline {
agent any
triggers {
pollSCM('[1]')
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'main' or 'refs/heads/main' does not work; those are branch specifiers configured in SCM settings.
Cron schedules trigger polling regardless of branch; branch filters are set separately.
✗ Incorrect
pollSCM requires a cron expression like H/5 * * * * to schedule SCM polling for changes.
3fill in blank
hardFix the error in the Jenkinsfile to archive test results.
Jenkins
post {
always {
[1] artifacts: '**/test-results/*.xml', allowEmptyArchive: true
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'archive' causes a syntax error.
Using 'saveArtifacts' is not a Jenkins step.
✗ Incorrect
The correct Jenkins step to archive files is archiveArtifacts.
4fill in blank
hardFill both blanks to define a Jenkins pipeline with environment variables and a build step.
Jenkins
pipeline {
agent any
environment {
APP_ENV = '[1]'
}
stages {
stage('Build') {
steps {
[2] 'build.sh'
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' instead of 'sh' causes errors.
Setting APP_ENV to 'development' is valid but not the expected answer here.
✗ Incorrect
Set APP_ENV to 'production' and use sh to run the build script.
5fill in blank
hardFill all three blanks to create a Jenkins pipeline that checks out code, runs tests, and archives results.
Jenkins
pipeline {
agent any
stages {
stage('Checkout') {
steps {
[1] scm
}
}
stage('Test') {
steps {
[2] 'runTests.sh'
}
}
}
post {
always {
[3] artifacts: '**/test-results/*.xml'
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' instead of 'sh' causes errors.
Using 'archive' instead of 'archiveArtifacts' causes errors.
✗ Incorrect
Use checkout to get code, sh to run tests, and archiveArtifacts to save test results.