0
0
Jenkinsdevops~20 mins

Docker Pipeline plugin in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Pipeline Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of Docker Pipeline build step
What is the output of the following Jenkins Pipeline snippet using the Docker Pipeline plugin?
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        script {
          def img = docker.build('my-image:latest')
          echo img.id
        }
      }
    }
  }
}
AThe image ID string of the built Docker image, e.g., sha256:abc123...
BThe literal string 'my-image:latest'
CAn error: 'docker.build' is not a valid method
DThe container ID of a running container
Attempts:
2 left
💡 Hint
The docker.build() method returns an image object with an id property.
🧠 Conceptual
intermediate
1:30remaining
Understanding Docker Pipeline plugin's 'inside' method
In Jenkins Docker Pipeline plugin, what does the 'inside' method do when called on a Docker image object?
APushes the Docker image to a remote registry.
BBuilds a new Docker image from the current workspace.
CRuns the given block of pipeline steps inside a container created from the image.
DRemoves the Docker image from the local Docker host.
Attempts:
2 left
💡 Hint
Think about running commands inside a container environment.
🔀 Workflow
advanced
2:30remaining
Correct order of Docker Pipeline plugin steps to build, test, and push
Arrange the following Docker Pipeline plugin steps in the correct order to build an image, run tests inside it, and then push it to a registry.
A1,4,2,3
B1,2,4,3
C4,2,1,3
D4,1,2,3
Attempts:
2 left
💡 Hint
You must define the image variable before using it.
Troubleshoot
advanced
2:00remaining
Diagnosing Docker Pipeline plugin authentication failure
You get an error 'unauthorized: authentication required' when running 'image.push()' in Jenkins Docker Pipeline plugin. What is the most likely cause?
AThe Dockerfile has syntax errors.
BDocker registry credentials are not configured or not passed to the pipeline.
CThe Jenkins agent does not have Docker installed.
DThe Docker image was not built before pushing.
Attempts:
2 left
💡 Hint
Pushing requires authentication to the registry.
Best Practice
expert
3:00remaining
Best practice for cleaning up Docker images in Jenkins pipeline
Which approach is best to avoid disk space issues caused by leftover Docker images when using the Docker Pipeline plugin in Jenkins?
AUse 'docker.image(...).remove()' after pushing the image to clean up local images.
BManually delete images on the Jenkins agent outside the pipeline.
CDo not build images in the pipeline; use pre-built images only.
DRestart the Jenkins server daily to clear Docker cache.
Attempts:
2 left
💡 Hint
Cleaning up images programmatically after use is efficient.