Prevent Gitlab CI Runners from running tasks unless tagged - gitlab

Gitlab jobs and runners can be tagged - so only runners with the tag can run the job. See documentation here: http://docs.gitlab.com/ce/ci/yaml/README.html#tags
I want to ensure that my runners that have tags only pick up tagged jobs. Currently jobs without any tags are eligible to run on these runners too.
Can this be done?

During the Registration process of the runner: https://docs.gitlab.com/runner/register/index.html
Choose whether the Runner should pick up jobs that do not have tags, you can change this later in GitLab's UI (defaults to false):
In the Admin panel https://<SERVER>/admin/runners
And in the config dialog of your specific runner (URL: https://<PROJECT_URL>/settings/ci_cd)
...you can set the option, to only run tagged jobs.
If you then also tag your jobs accordingly, you have reached your goal.
e.g.:
job:
tags:
- ruby
- postgres

Related

Cannot find how my jobs are bound to runners

I have a pipeline set up on Gitlab, within which my project is built and unit tests are run every time I commit a change to "developer" git branch.
Recently I've updated versions of some libraries in the project and after that builds on CICD started to fail and says that node.js version should be updated.
As I undestand I need to somehow edit settings of a container in which builds are run.
We have our own gitlab instance. As I see from the settings there are group of shared runners, used from many projects.
How can I find out which of those runners are used for my project? in the Gitlab GUI I can see tags assigned to the shared runners, but I don't see any tags in my .gitlab-ci.yml
Gitlab version is 15.4.2-ee
self-managed
If its not tagged it will run on any runner which is configured to run untagged jobs. Not just on any runner. By default runners don't run untagged jobs.

Gitlab: How to run a deploy job on a tagged version / release?

I have created several releases of my backend service in gitlab. Now I want to be able to pick one of them and run the deployment job in my gitlab pipeline on it. SO that the specific version gets deployed. (I'm creating release notes to each release so I can pick which release should now get deployed.)
This is my deployment job in the gitlab-ci.yml:
So far I have used this job like this: When a feature branch was merged into the master and the stand could be deployed and passed all the tests, then the job was triggered manually in the pipeline overview page. Now that I'm using tags to tag each new master version, I want to be able to deploy a version/release from the tags.
Does anyone have an idea how this could work in principle? It would be best if I had a dropdown menu where I can select one of the releases and then trigger the deployment job for it.
The job needs to not get run in the master pipeline, but in the tags pipeline
only:
refs:
- tags
when: manual
This way I can copy the tag of the version that I want to deploy:
and search for it in the pipelines overview page to then trigger the deploy job manually:

How to add available shared runners to GitLab project?

Only one gitlab runner is available in my project. However, in the runner page I have multiple other runners listed. How do I add these runners to the project such that a runner will be randomly selected to execute the build? The runners are running in Docker containers and I am using a self-managed version of GitLab.
These are the runners I have available
Only runner1 is currently shown in /settings/cicd under Runners:
runner1
Basically, if you go by runners there are actually three types of a runner in Gitlab
Specific: Only for Specific Project
Group: For all projects in the particular group (if need more info on groups https://docs.gitlab.com/ee/user/group)
Shared: These will be available for every project in the GitLab
It will be difficult to specify here that how we can configure the runners but I can point to documentation from where we actually configured our Runners
https://docs.gitlab.com/ee/ci/runners/
Also to make a note of tagging is a very important task that needs to be done so that you can use your runners with your requirement like you said you want to use runners randomly from the list then all the runners in the list should have a common tag that can be further used in your .gitlab-ci.yml file.
eg. We have tag runners as per the AWS ec2 instance size so (like macro, small, medium, large, etc) so that people using can use the runners as per the requirement of there job)
job1:
tags:
- shared-large-runner
job2:
tags:
- shared-micro-runner
Note: you can have multiple tags for a single runner for better control over its usage.
Hopefully, this helps!!
Looking at your screenshot, to be able to use group runners, your project just need to be inside that group
Because the group tag shows that the runner was configured just to accept jobs from one group
I think you have one runner for each group, this is the reason that your project only have the runner1

Find job tags from Gitlab CI API

Is there a way of finding out what tags (Gitlab CI tags, not git tags) a job has from the API?
As background, we are having some issues with contention on our CI pipeline. The runners are selected based on tags, and I want to log what tags are being used/built the most.
For instance if in my .gitlab-ci.yml file I have
build_thing:
stage: build
tags: [some_tag]
script:
- bash build.sh
Is there a way I can use the gitlab jobs API to determine show the tags (some_tag) of that job? I have not been able to find any API endpoints that show this in the documentation.
I am aware that I can look at what tags the active runners have, but unfortunately that is not enough information, as they can have different combinations of tags that overlap the jobs/pipelines.

How to isolate a gitlab runner to process specific environment or stage

I want to use gitlab runners for our builds and our deployment to QA. Can I set up a second runner that ONLY does deployments, or just a specific environment? I don't see a way to do this. (Gitlab.com/private runners)
Found it. This can be achieved using tags. CI runners can be configured to run only jobs that have specific tags, and tags can be applied to jobs.

Resources