1. Updating the Deployment YAML
The deployment YAML file defines the image that Kubernetes will run. For example, the file may look like this:
2. Jenkins Pipeline Stage to Update the Image Tag
The Jenkins pipeline stage named “K8S Update Image Tag” is designed to update the image tag and is executed only on pull request branches (i.e., branches whose names start with “PR”). This stage performs the following actions:- Clones the manifest repository from the main branch.
- Changes into the Kubernetes directory.
- Creates a new feature branch using the Jenkins environment variable
$BUILD_ID. - Utilizes the
sedcommand to update the image tag in the deployment YAML file to match the commit hash stored in$GIT_COMMIT. - Configures Git, commits the change, and pushes the feature branch to the remote repository.
3. Configuring Jenkins Credentials
Before committing the changes, Jenkins must be configured with the appropriate credentials. A Gitea (or GitHub) token is stored in Jenkins and referenced as the environment variable GITEA_TOKEN. An example environment section in the Jenkinsfile is as follows:To generate the Gitea token, navigate to your repository’s settings (in Gitea, for example) and create a new access token with read/write repository permissions.

4. Verifying the Process
Once the Jenkins pipeline runs, a new feature branch (for example, feature-1) is created in the manifest repository with the updated deployment configurations. You can verify this by inspecting the repository branches:



Conclusion
This lesson demonstrated how to automate the update of a Kubernetes deployment’s Docker image tag using Jenkins. By cloning the manifest repository, creating a feature branch, updating the YAML file using thesed command, and pushing changes with proper authentication, you can seamlessly integrate with Argo CD. The updated manifest is synchronized to the cluster only after merging the changes into the main branch, ensuring continuous deployment consistency.
Moving forward, we will explore automating the pull request process to merge manifest changes from feature branches into the main branch.
Thank you.