Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start a Jenkins pipeline with a declarative syntax.
Jenkins
pipeline {
agent any
stages {
stage('Build') {
steps {
[1] 'echo Building...'
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' or 'execute' which are not Jenkins pipeline steps.
✗ Incorrect
The sh step runs shell commands in Jenkins pipelines.
2fill in blank
mediumComplete the code to add a post-build action that always runs.
Jenkins
post {
[1] {
echo 'Cleaning up workspace'
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'failure' or 'success' which run only on those results.
✗ Incorrect
The always block runs regardless of build result.
3fill in blank
hardFix the error in the stage name to enable proper visualization.
Jenkins
stage('[1]') { steps { echo 'Testing...' } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces in stage names causing visualization issues.
✗ Incorrect
Stage names should avoid spaces for better visualization; TestStage is valid.
4fill in blank
hardFill both blanks to correctly define a parallel stage with two branches.
Jenkins
parallel {
branch1: {
steps {
[1] 'echo Branch 1'
}
}
branch2: {
steps {
[2] 'echo Branch 2'
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing different steps causing inconsistent execution.
✗ Incorrect
The sh step runs shell commands in both branches.
5fill in blank
hardFill all three blanks to add a timeout and catch errors in a scripted pipeline.
Jenkins
try { timeout(time: [1], unit: '[2]') { [3] { echo 'Running long task' } } } catch (err) { echo "Error: ${err}" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase units or missing the node block.
✗ Incorrect
Timeout is set to 30 minutes, and node block runs the steps.