Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to run two test stages in parallel in Jenkins pipeline.
Jenkins
pipeline {
agent any
stages {
stage('Parallel Tests') {
steps {
parallel {
test1: {
echo 'Running Test 1'
},
test2: [1]
}
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] or parentheses () instead of braces {} for parallel stages.
Forgetting to wrap the steps inside braces.
✗ Incorrect
In Jenkins pipeline, parallel stages are defined as blocks with braces {}. So the correct syntax for the second parallel stage is { echo 'Running Test 2' }.
2fill in blank
mediumComplete the code to define parallel stages with names 'Unit Tests' and 'Integration Tests'.
Jenkins
parallel {
[1]: {
echo 'Running Unit Tests'
},
integrationTests: {
echo 'Running Integration Tests'
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dashes '-' in stage names which is invalid syntax.
Using uppercase letters at the start which may cause confusion.
✗ Incorrect
Stage names in Jenkins pipeline should be valid Groovy identifiers without special characters or spaces. 'unitTests' is a valid camelCase identifier.
3fill in blank
hardFix the error in the parallel block by completing the missing keyword.
Jenkins
pipeline {
agent any
stages {
stage('Tests') {
steps {
[1] {
testA: {
echo 'Test A'
},
testB: {
echo 'Test B'
}
}
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'stages' or 'steps' instead of 'parallel' causes syntax errors.
Omitting the keyword entirely.
✗ Incorrect
The keyword 'parallel' is required to run multiple branches at the same time in Jenkins pipeline.
4fill in blank
hardFill both blanks to create a parallel block with two test stages that each run a shell command.
Jenkins
parallel {
testOne: {
sh [1] 'echo Test One'
},
testTwo: {
sh [2] 'echo Test Two'
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for the argument name causes errors.
Using 'command' instead of 'script' as the argument name.
✗ Incorrect
The 'sh' step in Jenkins pipeline uses the 'script' argument as a string to run shell commands. Double quotes are preferred for Groovy strings.
5fill in blank
hardFill all three blanks to define a parallel block with three test stages, each echoing a different message.
Jenkins
parallel {
testA: {
echo [1]
},
testB: {
echo [2]
},
testC: {
echo [3]
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the messages between stages.
Forgetting to use quotes around the echo messages.
✗ Incorrect
Each parallel stage should echo its own message. The correct messages are 'Running Test A', 'Running Test B', and 'Running Test C'.