Interview Prep/Real-World Interview/Write-a-pipeline tasks

Write a GitOps image-bump step: CI updates the image tag in a manifests repo.

AdvancedHands-onWrite-a-pipeline tasks
Answer
- name: Bump image in env repo
  env:
    GH_TOKEN: ${{ secrets.ENV_REPO_TOKEN }}
    TAG: ${{ github.sha }}
  run: |
    git clone "https://x-access-token:${GH_TOKEN}@github.com/org/env-repo.git"
    cd env-repo/apps/api/overlays/staging
    kustomize edit set image "myrepo/api=myrepo/api:${TAG}"
    git config user.name "ci-bot"
    git config user.email "[email protected]"
    git commit -am "api: deploy ${TAG::7} to staging"
    for i in 1 2 3; do git pull --rebase && git push && break; sleep $((i*2)); done

Key trick → CI never talks to the cluster. Argo CD watches the env repo and syncs it. The pull-rebase-push retry loop handles concurrent pushes from other services' pipelines.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-pipeline tasks