Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Gitlab CI tags

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.

like image 289
RiddleMeThis Avatar asked Apr 24 '17 19:04

RiddleMeThis


People also ask

What are tags in GitLab CI?

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.

What is the use of tag in GitLab?

Tags help you mark certain deployments and releases for later reference. Git supports two types of tags: Annotated tags: An unchangeable part of Git history. Lightweight (soft) tags: Tags that can be set and removed as needed.

What is a Git tag vs branch?

The difference between tags and branches are that a branch always points to the top of a development line and will change when a new commit is pushed whereas a tag will not change. Thus tags are more useful to "tag" a specific version and the tag will then always stay on that version and usually not be changed.

How do you list a tag?

In order to list Git tags, you have to use the “git tag” command with no arguments. You can also execute “git tag” with the “-n” option in order to have an extensive description of your tag list. Optionally, you can choose to specify a tag pattern with the “-l” option followed by the tag pattern.


1 Answers

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.

like image 114
sgy Avatar answered Oct 02 '22 09:10

sgy