Understanding Gitlab CI tags
Asked Answered
D

3

72

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.

Delsiedelsman answered 24/4, 2017 at 19:10 Comment(0)
F
102

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.

Flyboat answered 2/5, 2017 at 19:37 Comment(3)
Do I need to specify a tag when creating the runner?Caernarvonshire
Yes, that can be done on the runner side at the time you register it. After that, you need the rights on the project if you want to edit the runner's configuration (including tags), and the changes are done on the gitlab server side. In the page that lists your runners for that project, you have a small edit icon (a pencil) that take you to the page where you can edit the tags.Smacking
I've used gitlab runner to build DEB files and I ended up using these tags - it accepts regex as well: tags: - /^.*build_v\..*$/ Where even the assigned gitlab-runner itself has to be configured to capture this regex type of TAG. I've then used the version number to build my packages. So if I've commited a tag with "build_vX.Y.Z" the runner kicked in.Delsiedelsman
K
6

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
Kismet answered 18/1, 2018 at 12:7 Comment(0)
G
2

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
Goodson answered 23/7, 2021 at 12:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.