Updating the Jenkins Pipeline
To begin, modify your Jenkinsfile by adding a new stage dedicated to pushing the Docker image. Start with a simple stage that builds the Docker image:Installing the Docker Pipeline Plugin
To take full advantage of Jenkins’ capabilities with Docker, install the Docker Pipeline plugin by navigating to the Plugins section in Jenkins. This plugin provides functions for handling Docker images, configuring registries, and accessing global variables.

Configuring Docker Registry Credentials
For secure image pushes, configure your Docker Hub credentials in Jenkins:- Go to the Credentials section.
- Create a new entry of type “Username with password.”
- Label the description as “Docker Hub credentials” for easy identification.
The default registry URL is set to index.docker.io/v1. If you are using a different container registry, make sure to specify its endpoint in your Jenkins configuration.


Modifying the Pipeline Stage for Registry Authentication
Once the credentials are in place, update your Jenkins pipeline stage to include Docker Hub authentication. Wrap the push command within awithDockerRegistry block, as seen below:
Triggering and Verifying the Pipeline
After updating the Jenkinsfile, commit and push your changes to the repository. This action triggers the pipeline. During execution, you might see commands similar to the following in the build log:
Summary
This article demonstrated how to build a CI pipeline in Jenkins that:- Builds a Docker image.
- Executes a vulnerability scan using Trivy.
- Pushes the Docker image to Docker Hub using the Docker Pipeline plugin with securely configured credentials.