diff --git a/infra/k8s/argo/compile-and-deploy-template.yaml b/infra/k8s/argo/compile-and-deploy-template.yaml index 36fd98762..e69fe0163 100644 --- a/infra/k8s/argo/compile-and-deploy-template.yaml +++ b/infra/k8s/argo/compile-and-deploy-template.yaml @@ -123,15 +123,24 @@ spec: TAG="${PREFIX}.${NEXT_N}" echo "Creating tag: ${TAG} at ${SHA}" - # Create the tag - RESULT=$(curl -sf -X POST \ + # Create the tag (tolerate failure if tag already exists) + HTTP_CODE=$(curl -s -o /tmp/tag_response -w "%{http_code}" -X POST \ -H "PRIVATE-TOKEN: ${GITLAB_PAT}" \ -d "tag_name=${TAG}" \ -d "ref=${SHA}" \ "${GITLAB}/api/v4/projects/${PROJECT_ID}/repository/tags") - echo "$RESULT" | grep -q "$TAG" || { echo "Tag creation failed: $RESULT"; exit 1; } - echo "Tag ${TAG} created successfully" + RESULT=$(cat /tmp/tag_response 2>/dev/null || echo "{}") + + if [ "$HTTP_CODE" = "201" ]; then + echo "Tag ${TAG} created successfully" + elif [ "$HTTP_CODE" = "400" ] && echo "$RESULT" | grep -q "already exists"; then + echo "Tag ${TAG} already exists — reusing" + else + echo "WARN: Tag creation returned HTTP ${HTTP_CODE}: ${RESULT}" + echo "Falling back to dev tag" + TAG="dev-$(echo $SHA | cut -c1-8)" + fi mkdir -p /tmp/outputs echo -n "$TAG" > /tmp/outputs/tag