Consider this Jenkins pipeline snippet that pushes a Docker image to a registry:
stage('Push Image') {
steps {
script {
docker.withRegistry('https://myregistry.example.com', 'registry-credentials') {
def appImage = docker.build('myapp:latest')
appImage.push()
}
}
}
}What will Jenkins output if the push is successful?
Think about what Jenkins logs when a Docker image push succeeds inside docker.withRegistry.
When the image push succeeds, Jenkins logs a success message indicating the image name and registry URL.
You want to push Docker images to a private registry from Jenkins. Which credential type should you configure in Jenkins to authenticate properly?
Docker registries usually require a username and password for login.
Docker registries authenticate using username and password, so Jenkins credentials of type 'Username with password' are needed.
Given this Jenkins pipeline snippet:
stage('Push Image') {
steps {
script {
def appImage = docker.build('myapp:latest')
appImage.push()
}
}
}The push step fails with an authentication error. What is the most likely cause?
Think about how Jenkins provides credentials to Docker commands.
Without docker.withRegistry, Jenkins does not pass credentials to Docker, causing authentication failure on push.
Arrange these steps in the correct order to build and push a Docker image to a registry in Jenkins:
Think about when authentication must happen relative to building and pushing.
You first define the image name and tag, then authenticate to the registry, then build the image, and finally push it.
Which of the following practices best improves security when pushing Docker images to a registry in Jenkins pipelines?
Consider how Jenkins manages sensitive information securely.
Using Jenkins credentials plugin securely stores and injects sensitive data without exposing it in code or logs.