How to tag source code using gitlabCI We got gitlab new to our environment and trying to create some CI CD pipelines using gitlab CI. I have got some better progress with running some maven goals, creating pipelines and archiving artifacts using my .gitlab-ci.yml as below. I tried to give give tags after script which doesnt work. Now, I am trying to figure out how can I automate git tags to my sourcecode. I would like to create tag for sourcecode after master branch got successful build. we are using Semantic versions to tag our source code. Finally, so whenever master got successful build I would like to create a tag to my master branch.

image: maven:3.5-jdk-8-alpine

stages:
 - build
 - deploy
 - tag

maven_build:
  stage: build

  script:
   - mvn clean package
artifacts:
 paths:
 - target/*.jar

after_script:
   - ls -a
   - cd target &amp;&amp; ls -a
   - git --version
   - git tag -a 1.0.15 -m "Version created by gitlab-ci Build"
   - git push origin 1.0.15
only:
  - master


logs:

Running after script...
$ ls -a
.
..
.git
.gitignore
.gitlab-ci.yml
 LICENSE
README.md
pom.xml
src
target
$ cd target &amp;&amp; ls -a
.
..
apidocs
classes
generated-sources
generated-test-sources
javadoc-bundle-options
maven-archiver
maven-simple-0.2-SNAPSHOT-javadoc.jar
maven-simple-0.2-SNAPSHOT-sources.jar
maven-simple-0.2-SNAPSHOT.jar
maven-status
surefire-reports
test-classes
Uploading artifacts...
target/maven-simple-0.2-SNAPSHOT-javadoc.jar: found 1 matching files 
Uploading artifacts to coordinator... ok            id=60598296 
responseStatus=201 Created token=Gu-eH1es


Job succeeded
I tried to change docker image and added couple steps for git tag. Below is the answer worked for me,

image: maven

stages:
- build
- deploy
- tag

maven_build:
stage: build

  script:
   - mvn clean package
   artifacts:
  paths:
   - target/*.jar

  after_script:
   - ls -a
   - cd target &amp;&amp; ls -a
   - git --version
   - git remote remove origin
   - git remote set-url origin https://"username:passwd"@gitlab.com/accountname/projectname
   - git tag -a 1.0.15 -m "Version created by gitlab-ci Build"
   - git push origin 1.0.15
  only:
    - master