0
0
Jenkinsdevops~10 mins

When to use scripted over declarative in Jenkins - Interactive Code Practice

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

Complete the code to start a scripted Jenkins pipeline.

Jenkins
node {
    stage('Build') {
        [1] 'echo Building...'
    }
}
Drag options to blanks, or click blank then click option'
Ash
Bsteps
Cscript
Dstage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'steps' instead of 'sh' inside scripted pipeline.
Trying to use 'stage' as a command.
2fill in blank
medium

Complete the code to define a variable in scripted pipeline.

Jenkins
node {
    def message = [1]
    echo message
}
Drag options to blanks, or click blank then click option'
AHello from scripted
B'Hello from scripted'
C"Hello from scripted"
Dmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string.
Using variable name instead of string value.
3fill in blank
hard

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

Jenkins
node {
    stage('Test') {
        [1] 'echo Testing...'
    }
}
Drag options to blanks, or click blank then click option'
Ascript.sh
Bsteps.sh
Csh
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'steps.sh' which is for declarative pipelines.
Using 'run' which is not a Jenkins step.
4fill in blank
hard

Fill both blanks to create a scripted pipeline with a conditional stage.

Jenkins
node {
    if (env.BRANCH_NAME == [1]) {
        stage([2]) {
            sh 'echo Deploying...'
        }
    }
}
Drag options to blanks, or click blank then click option'
A'main'
B"Deploy"
C'Deploy'
Dmain
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted branch name or stage name.
Mixing single and double quotes incorrectly.
5fill in blank
hard

Fill all three blanks to define a scripted pipeline with a loop and shell command.

Jenkins
node {
    for (int i = 0; i < [1]; i++) {
        stage([2]) {
            sh [3]
        }
    }
}
Drag options to blanks, or click blank then click option'
A3
B"Loop Stage"
C'echo Running iteration ' + i
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong loop count.
Not quoting stage name.
Not quoting shell command.