0
0
Jenkinsdevops~10 mins

Groovy syntax in pipelines 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 define a simple Jenkins pipeline stage named 'Build'.

Jenkins
stage('[1]') {
    steps {
        echo 'Building the project'
    }
}
Drag options to blanks, or click blank then click option'
ATest
BClean
CBuild
DDeploy
Attempts:
3 left
💡 Hint
Common Mistakes
Using a stage name that does not match the task, like 'Test' or 'Deploy'.
Leaving the stage name blank.
2fill in blank
medium

Complete the code to declare a variable named 'version' with value '1.0' in a Jenkins pipeline script.

Jenkins
def [1] = '1.0'
Drag options to blanks, or click blank then click option'
Aversion
Benv
CbuildNumber
DstageName
Attempts:
3 left
💡 Hint
Common Mistakes
Using reserved words like 'env' as variable names.
Using a variable name unrelated to the task.
3fill in blank
hard

Fix the error in the code to correctly run a shell command in a Jenkins pipeline step.

Jenkins
steps {
    sh '[1]'
}
Drag options to blanks, or click blank then click option'
Aecho Hello World
Bwrite('Hello World')
Cconsole.log('Hello World')
Dprint('Hello World')
Attempts:
3 left
💡 Hint
Common Mistakes
Using programming language print functions instead of shell commands.
Missing quotes around the shell command.
4fill in blank
hard

Fill both blanks to create a Jenkins pipeline script that runs a shell command only if the branch is 'main'.

Jenkins
if (env.BRANCH_NAME [1] '[2]') {
    sh 'echo Deploying to production'
}
Drag options to blanks, or click blank then click option'
A==
B!=
Cmain
Ddevelop
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' for equality check.
Using the wrong branch name like 'develop'.
5fill in blank
hard

Fill all three blanks to create a map in Groovy with keys 'name' and 'status', and a condition to include only if status is 'success'.

Jenkins
def result = [[1]: 'Build', [2]: 'success']
if (result.[3] == 'success') {
    echo 'Build succeeded'
}
Drag options to blanks, or click blank then click option'
Aname
Bstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up keys and values.
Using incorrect key names in the condition.