Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a Jenkins pipeline block.
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' instead of 'sh' causes errors.
✗ Incorrect
The sh step runs shell commands in Jenkins pipelines.
2fill in blank
mediumComplete the code to specify the agent as a Docker container.
Jenkins
pipeline {
agent {
docker {
image '[1]'
}
}
stages {
stage('Test') {
steps {
sh 'echo Testing...'
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an unrelated image like 'mysql:5.7' for a build agent.
✗ Incorrect
The image field specifies the Docker image to use as the agent environment.
3fill in blank
hardFix the error in the stage declaration by completing the missing keyword.
Jenkins
pipeline {
agent any
stages {
[1]('Deploy') {
steps {
sh 'echo Deploying...'
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'step' or 'job' instead of 'stage' causes syntax errors.
✗ Incorrect
The correct keyword to define a stage is stage.
4fill in blank
hardFill both blanks to create a post-build action that always runs a cleanup step.
Jenkins
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'echo Building...'
}
}
}
post {
[1] {
[2] {
sh 'echo Cleaning up...'
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'success' instead of 'always' will skip cleanup on failure.
✗ Incorrect
The post block uses conditions like always and inside it the steps block defines commands to run.
5fill in blank
hardFill all three blanks to define an environment variable and use it in a shell step.
Jenkins
pipeline {
agent any
environment {
[1] = '[2]'
}
stages {
stage('Print') {
steps {
sh 'echo [3]'
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable name and reference inconsistently causes empty output.
✗ Incorrect
Define the variable name as MY_VAR, assign it the string HelloWorld, and use $MY_VAR to access it in shell.