GitOps With Jenkins: Jenkins for CI and Argo CD for CD, Updating Manifests and Image Tags in Git
Push vs Pull Deployment
| Push (Jenkins deploys) | Pull (GitOps) | |
|---|---|---|
| Who changes the cluster | Jenkins runs kubectl or helm with cluster credentials | An agent inside the cluster (Argo CD or Flux) pulls from Git and applies it |
| Cluster credentials | Stored in Jenkins (a big target) | Stay in the cluster. Jenkins never holds them |
| Source of truth | The last pipeline run | Git: you can read exactly what should be running |
| Drift | Manual changes stay unnoticed | Detected and, if enabled, corrected automatically |
| Rollback | Re-run a pipeline | git revert |
| Audit | Jenkins logs | Git history: who, what, when and the review |
The Split
text
APP repo (code) CONFIG repo (manifests / Helm values per environment)
│ push ▲ Jenkins commits the new image tag
▼ │
JENKINS: build ─ test ─ scan ─ push image ─┘
│ (Git change)
â–¼
ARGO CD in the cluster: sees the change ─► syncs ─► health check
Jenkins = CI. Argo CD = CD.
- The application repository holds source code and the Jenkinsfile
- The config repository holds Kubernetes YAML, Kustomize overlays or Helm values for
dev,stagingandprod - Separate repositories mean app builds do not trigger on config changes, and permissions can differ
Config Repository Layout
text
shop-config/
├─ base/
│ ├─ deployment.yaml
│ ├─ service.yaml
│ └─ kustomization.yaml
└─ overlays/
├─ dev/ kustomization.yaml (images: newTag: 128-3f9c2ab)
├─ staging/ kustomization.yaml
└─ prod/ kustomization.yaml
yaml
# overlays/dev/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
namespace: shop-dev
images:
- name: registry.example.com/team/shop
newTag: "127-a1b2c3d"
Jenkins Updates the Tag in Git
groovy
stage('Update config repo') {
when { branch 'main' }
steps {
withCredentials([usernamePassword(credentialsId: 'config-repo-bot', usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) {
sh '''
set -e
rm -rf config && git clone https://${GIT_USER}:${GIT_PASS}@git.example.com/team/shop-config.git config
cd config/overlays/dev
kustomize edit set image registry.example.com/team/shop=registry.example.com/team/shop:${TAG}
git config user.name "jenkins-bot"
git config user.email "jenkins-bot@example.com"
git add kustomization.yaml
git commit -m "dev: shop ${TAG} (build ${BUILD_NUMBER}, commit ${GIT_COMMIT})" || echo "nothing to commit"
git push origin HEAD:main
'''
}
}
}
Safer: open a pull request: For staging and production, have Jenkins push a branch and open a pull request (use the GitHub CLI
gh pr create). A person reviews and merges, which is the approval. The merge triggers Argo CD.
bash
git checkout -b promote-staging-${TAG}
kustomize edit set image registry.example.com/team/shop=registry.example.com/team/shop:${TAG}
git commit -am "staging: shop ${TAG}" && git push -u origin HEAD
gh pr create --title "Promote shop ${TAG} to staging" --body "Build ${BUILD_URL}. Tests passed. Scan clean." --base mai
Argo CD Application
yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: shop-dev
namespace: argocd
spec:
project: shop
source:
repoURL: https://git.example.com/team/shop-config.git
targetRevision: main
path: overlays/dev
destination:
server: https://kubernetes.default.svc
namespace: shop-dev
syncPolicy:
automated: {prune: true, selfHeal: true} # dev: auto-sync; prod: leave manual or use PR gate
syncOptions: [CreateNamespace=true]
Wait for the Result in Jenkins (Optional)
groovy
stage('Wait for Argo CD') {
steps {
withCredentials([string(credentialsId: 'argocd-token', variable: 'ARGOCD_AUTH_TOKEN')]) {
sh '''
argocd --server argocd.example.com --grpc-web app sync shop-dev --revision main
argocd --server argocd.example.com --grpc-web app wait shop-dev --health --timeout 300
'''
}
}
}
Benefits and Costs
| Benefits | Costs |
|---|---|
| Cluster credentials never leave the cluster | Two repositories and one more tool to learn |
| Git is the audit trail and the rollback tool | Deployment result is not in the Jenkins job unless you add a wait step |
| Automatic drift correction | Secrets need a GitOps-friendly approach (Sealed Secrets, External Secrets, SOPS) |
| Easy to rebuild a cluster from Git | Needs discipline: no manual kubectl edit in production |
Practice Tasks
- Create an app repo and a config repo with Kustomize overlays
- Write the Jenkins stage that updates the dev overlay tag and pushes it
- Install Argo CD in a lab cluster and create the Application
- Make staging promotion a pull request created by Jenkins
- Roll back a bad release with
git revertand watch the cluster follow
Conclusion
In GitOps, Jenkins stays the CI engine: build, test, scan, push the image and commit the new tag to a config repository. Argo CD or Flux inside the cluster pulls and applies it, so cluster credentials stay inside, Git is the audit trail and rollback is a revert. Use pull requests for staging and production promotion.
Quick Summary: push vs pull; app repo vs config repo; kustomize edit set image from Jenkins; PR promotion; Argo CD Application; wait step; benefits/costs.

