gitlab CI - pushing a tag fails

680 Views Asked by At

I am trying to push the tag in tagging stage of pipeline, I have a logic to form a tag and push it back to repo. Now to push the tag, I've created project access token and have below in my gitlab yml. The output is with "set -x"

$ git push "${TEST_TAG}" "${CI_REPOSITORY_URL}"
++ git push v1.0.0 https://gitlab-ci-token:[MASKED]@gitlab.demo.com/demouser/demoproject.git
error: src refspec https://gitlab-ci-token does not match any

queries:

  1. this is because I haven't set the variable with access token value in gitlab yml? also if I do so, doesn't it expose the token?
  2. what am I missing here?

Also, what would be the best practice as of 2022 to do so. Thanks.

1

There are 1 best solutions below

0
torek On
git push "${TEST_TAG}" "${CI_REPOSITORY_URL}"

These arguments are in the wrong order. The URL (or <remote>) argument must be the first positional argument. The remaining arguments are refspecs. The simplest form of a refspec is a branch or tag name: Git will take that and find the full spelling of that name.

The second simplest form is to put a branch or tag name on the left side of a colon, and another branch or tag name on the right side of a colon. The left side is then the source ref and the right side is the destination. Your refspec was:

https://gitlab-ci-token

so the source part was https. Git tries to find a branch or tag whose name is https. There isn't one, hence the error message:

error: src refspec https://gitlab-ci-token does not match any

(not a very good error message, in my opinion, but it's what you get).