0
0
Jenkinsdevops~10 mins

Why scripted pipelines offer flexibility in Jenkins - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a scripted pipeline stage.

Jenkins
stage('Build') {
    [1] 'echo Building...'
}
Drag options to blanks, or click blank then click option'
Ash
Bscript
Cbat
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'script' instead of 'sh' for shell commands.
Confusing 'bat' which is for Windows batch commands.
2fill in blank
medium

Complete the code to start a scripted pipeline with node allocation.

Jenkins
node( [1] ) {
    stage('Test') {
        echo 'Running tests'
    }
}
Drag options to blanks, or click blank then click option'
A'build'
B'agent'
C'node'
D'master'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'agent' which is a declarative pipeline term.
Using 'node' as a string inside the node block.
3fill in blank
hard

Fix the error in the scripted pipeline to run a shell command conditionally.

Jenkins
if (params.DEPLOY == 'true') {
    [1] 'echo Deploying application'
}
Drag options to blanks, or click blank then click option'
Ascript
Bsh
Cbat
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'script' instead of 'sh' inside the if block.
Using 'bat' on Unix systems.
4fill in blank
hard

Fill both blanks to create a map with stage names and their status in a scripted pipeline.

Jenkins
def stages = [[1]: 'SUCCESS', [2]: 'FAILURE']
Drag options to blanks, or click blank then click option'
A'Build'
B'Test'
C'Deploy'
D'Cleanup'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-string keys without quotes.
Mixing up stage names and statuses.
5fill in blank
hard

Fill all three blanks to define a scripted pipeline with a try-catch block for error handling.

Jenkins
try {
    [1] 'exit 1'
} catch (Exception [2]) {
    echo 'Caught error: ' + [3].toString()
}
Drag options to blanks, or click blank then click option'
Ash
Be
Dscript
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'script' instead of 'sh' inside try.
Using different variable names inconsistently in catch.