SLesslyTall
SLesslyTall

Reputation: 261

Add and push commit tag in GitLab CI/CD job

Is it possible to add and push a commit tag using the GitLab CI/CD configuration file?

In my use case I have a release stage that uploads a python package and it's associated documentation, and then only after those succeed I would like to tag the commit with the version number.

Upvotes: 4

Views: 6580

Answers (2)

Kristijonas
Kristijonas

Reputation: 151

GitLab exposes REST API for tagging. Example:

tag_it:
  stage: release
  script:
    - curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/tags?tag_name=test&ref=master"

See more info in https://docs.gitlab.com/ee/api/tags.html#create-a-new-tag.

Upvotes: 2

Nicolas Pepinster
Nicolas Pepinster

Reputation: 6221

Just add a job using your release stage in your .gitlab-ci.yml with these lines :

tag_commit:   
  stage: release   
  script:
    - git tag -a v1.0 <COMMIT_ID> -m "Message here"
    - git push origin v1.0

Upvotes: 3

Related Questions