Hello !
Am i quite confused by the result i get when trying to delete and recreate a tag from the pipeline…
Here is an my YAML example, using a var called GITLAB_PRIVATE_TOKEN containing a project access token with all rights checked.
stages:
- tag
tag-delivery:
stage: tag
image: node:17.3.0
script:
- PREPROD_TAGS="abc,def"
- THIS_GITLAB=$(echo $CI_PROJECT_URL | sed 's/https\?:\/\///')
- git remote add api-origin https://oauth2:${GITLAB_PRIVATE_TOKEN}@${THIS_GITLAB}
- git checkout ${CI_DEFAULT_BRANCH}
- git config user.email "${GITLAB_USER_EMAIL}"
- git config user.name "${GITLAB_USER_NAME}"
- IFS=', ' read -r -a array <<< $PREPROD_TAGS
- for THIS_TAG in "${array[@]}"; do
- git tag -l "$THIS_TAG"
- if [ $(git tag -l "$THIS_TAG") ]; then
- echo "tag $THIS_TAG already exists. Deleting and pushing changes ..."
- git push --delete api-origin "$THIS_TAG" -o ci.skip
- fi
- echo "tag $THIS_TAG does not exists. Creating and pushing changes ..."
- git tag -a $THIS_TAG -m "Test message for $THIS_TAG"
- git push api-origin $THIS_TAG
- done
First run : no pre-existing tags, tags abc and def are created. All seems OK.
Second run : tags are found, the messy stuff begins :
$ if [ $(git tag -l “$THIS_TAG”) ]; then
$ echo “tag $THIS_TAG already exists. Deleting and pushing changes …”
tag def already exists. Deleting and pushing changes …
$ git push --delete api-origin “$THIS_TAG” -o ci.skip
- [deleted] def
$ fi
$ echo “tag $THIS_TAG does not exists. Creating and pushing changes …”
tag def does not exists. Creating and pushing changes …
$ git tag -a $THIS_TAG -m “Test message for $THIS_TAG”
fatal: tag ‘def’ already exists
Any idea about what is wrong here ?
Thanks !