问题
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.
回答1:
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 it's Guid, click on the pen icon. On next page the tags can be modified.
回答2:
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
来源:https://stackoverflow.com/questions/43638979/understanding-gitlab-ci-tags