apiVersion: tekton.dev/v1 kind: Task metadata: name: git-gitops-sync annotations: tekton.dev/pipelines.minVersion: "0.19.0" tekton.dev/categories: GitOps tekton.dev/tags: git, helm, devops tekton.dev/displayName: "Update image tag in Helm values.yaml" tekton.dev/platforms: "linux/amd64" spec: description: | Updates the image.tag field in a Helm values.yaml file and commits the change to the corresponding GitOps repository derived from the application source repo. params: - name: context type: string default: "" description: context directory - name: repositoryUrl type: string description: Source repository URL (used to derive GitOps repo) - name: branch type: string default: main description: Git branch to push to - name: imageUrl type: string description: Full image URL (e.g. registry/app:v0.2.0) - name: valuesPath type: string description: Path to Helm values file (e.g. overlays/staging/values-staging.yaml) - name: commitMessage type: string default: "chore(gitops): update image tag" description: Commit message workspaces: - name: base steps: - name: update-and-push image: alpine:3.19 workingDir: /workspace env: - name: HOME value: /workspace/base/$(params.context)/home script: | #!/bin/sh set -e echo "๐Ÿ“ฆ Installing Git + yq..." apk add --no-cache git yq openssh REPO_URL="$(params.repositoryUrl)" GITOPS_REPO=$(echo "$REPO_URL" | sed 's/\.git$/-ops.git/') BRANCH="$(params.branch)" VALUES_PATH="$(params.valuesPath)" IMAGE="$(params.imageUrl)" TAG=$(echo "$IMAGE" | cut -d: -f2) echo "๐Ÿ“ฅ Cloning $GITOPS_REPO..." TMP_DIR=$(mktemp -d) git clone --branch "$BRANCH" "$GITOPS_REPO" "$TMP_DIR" cd "$TMP_DIR" echo "๐Ÿ›  Updating image.tag in $VALUES_PATH to $TAG" yq e ".image.tag = \"$TAG\"" -i "$VALUES_PATH" git add "$VALUES_PATH" git commit -m "$(params.commitMessage)" || echo "No changes to commit." git push origin "$BRANCH" echo "๐Ÿงน Cleaning up..." rm -rf "$TMP_DIR"