Understanding Gitlab CI tags

TaggingGitlabYaml

Tagging Problem Overview


I've read documentation, some articles and you might call me dumb, but this is my first time working with a concept like this.

  • I've registered runner with tag "testing"
  • created tag "testing" in gitlab
  • binded this runner, with particular project
  • I've also added the same tag e.g. "testing"in my local repo.

BUT how exactly is running my jobs dependent on those tags? Are all these operations necessary? If I push new code to repo, *.yml file is executed anyway as far as I tested.

So what if I want to run build only when I define a version in a commit?

IDK...

   git commit --tags "v. 2.0" -m "this is version 2.0" (probably not right)

But of course it should be universal, so I don't have to always tell, which tag to use to trigger the runner, but for example let him recognize numeric values.

As you can see, I'm fairly confused... If you could elaborate how exactly tags work, so I would be able to understand the concept, I would be really grateful.

Tagging Solutions


Solution 1 - Tagging

Tags for GitLab CI and tags for Git are two different concepts.

When you write your .gitlab-ci.yml, you can specify some jobs with the tag testing. If a runner with this tag associated is available, it will pickup the job.

In Git, within your repository, tags are used to mark a specific commit. It is often used to tag a version.

The two concepts can be mixed up when you use tags (in Git) to start your pipeline in GitLab CI. In your .gitlab-ci.yml, you can specify the section only with tags.

Refer to GitLab documentation for tags and only.

An example is when you push a tag with git:

$ git tag -a 1.0.0 -m "1.0.0"
$ git push origin 1.0.0

And a job in .gitlab-ci.yml like this:

compile:
    stage: build
    only: [tags]
    script:
        - echo Working...
    tags: [testing]    

would start using a runner with the testing tag.

By my understanding, what is missing in your steps is to specify the tag testing to your runner. To do this, go in GitLab into your project. Next to Wiki, click on Settings. Go to CI/CD Pipelines and there you have your runner(s). Next to its Guid, click on the pen icon. On next page the tags can be modified.

Solution 2 - Tagging

> Are all these operations necessary?

No, if all you have is one runner, or if you have many but do not care which runner runs your job, then there is no point in tagging runners/jobs.

> So what if I want to run build only when I define a version in a > commit?

job:
  only:
    - tags

Solution 3 - Tagging

Gitlab-tag: is for identifying a specific runner for your job. ref Git-tag: is versioning the commit. ref

Pushing a new repo

  • would generally be done via git client like pycharm (current example)

  • create/update code

  • commit

  • set a git-tag for the commit

  • enter image description here

  • push to remote along with tags

  • enter image description here

  • check the logs in the client app for eg in pycharm as below:

  • enter image description here

  • Now check the same in gitlab->Repo->tags

  • enter image description here

  • in gitlab job the same can be reviewed using export and the job result would have below:

  • enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRiddleMeThisView Question on Stackoverflow
Solution 1 - TaggingsgyView Answer on Stackoverflow
Solution 2 - TaggingAhmad AbdelghanyView Answer on Stackoverflow
Solution 3 - TaggingRama KrishnaView Answer on Stackoverflow