Article Updated on September 2022.
The GitLab version used for this post: is 13.9.4
Gitlab Runner Tags it’s our topic today. We will learn how to get all advantages of those features available on GitLab.
What is GitLab Runner Tags?
What kind of problem can the Tags resolve for us?
GitLab Runner is an application that operates with GitLab CI/CD to run jobs in a pipeline. And this application, “Runner,” could be installed in different operating systems and a computer on the cloud or virtual machine. So, we have that flexibility because it may require another operating system depending o which application we try to develop. So, for that reason, we may need a mechanism to select the proper Runner to build our application, which is the main goal for Gitlab Runner Tags.
Multiple Runner for different AWS Accounts.
Also, if your Runner is deployed on AWS Cloud on an EC2 instance, for example, and for a big company that holds more than one AWS account, it may require to deploy one Runner for each AWS Account. This approach could resolve many security issues because the deployment scripts may have full access to deploy your application, so we need to control the Runner’s access to our resources correctly.
For instance, you may have one AWS Account for Dev, QA, and Production environment, and which Runner only has permission to deploy on your account.
Isolate Projects Building Process
Which scenarios do we need to use tags?
Sometimes we may have different pipelines that require more resources like CPU, Memory to execute the pipeline. It’s an excellent approach to separate the heavy pipelines from the small projects. To avoid overloading the Runner and causing a bad experience for developers.
That approach was used in our example in our previous blog post, where we configured a Runner using AWS Fargate to build heavy pipelines. And because the AWS Fargate is not a good solution for small projects (due to the time to create an Executor), that takes less than 2 minutes to be executed. So the better choice it’s to make our project directly call the Runner from Fargate and leave the regular Runner for all other projects as default, using the proper Tags.
One Runner can have multiple tags or no tags at all.
It’s worth remembering that Gitlab Runner Tag is an optional configuration. At the same time, we can assign multiple Tags for one specific Runner.
Who can configure the Tags?
Only Administrators can assign Tags to the Runners.
How to configure Gitlab Runner Tags?
We have two approaches to configuring a new Tag on the Runner.
For the first one, we can assign tags to the Runner registration process. And the second way will be in the Administration section on the Web Interface.
Let’s see more details about both approaches.
Creating Gitlab Runner Tags on the Registration Process
sudo gitlab-runner register \ --url "https://gitlab.www.bitslovers.com/" \ --registration-token "THE_REGISTRATION_TOKEN" \ --executor "docker" \ --docker-image alpine:latest \ --description "docker-runner" \ --tag-list "docker,aws" \ --run-untagged="true" \ --locked="false"
The parameter —tag-list, it’s one that we can specify what the tags that we would like to assign to the Runner are. Also, there is another crucial parameter: —run-untagged. If you enable that option, the Runner will only pick up projects explicitly using the Runner’s tags.
If you do not enable that option, this Runner will be configured as “Shared Runner,” so Gitlab will share the Runner for any project that doesn’t specify a Tag.
Assigning Gitlab Runner Tags to the Administration area
To assign Tags to the Gitlab Runner, you need to navigate to the Administration area, and select your Runner and then edit the configuration, like the screenshot above:
on the Tags fields, you can type more than one Tag, separate by a comma.
How to use Gitlab Runner Tags
Use tags to run jobs on different platforms.
You can utilize tags to run several jobs on different platforms. For instance, if you own an OS X runner with a tag osx and, or a Windows runner with a tag
windows, you can execute a job on a specific platform:
c_job: stage: - build tags: - windows-10 script: - echo "Hi, welcome to www.bitslovers.com, %USERNAME%!" macos_job: stage: - build tags: - macosx script: - echo "Hi, welcome to www.bitslovers.com"
Or if you have a Fargate Runner configured with the “aws-fargate” tag:
build: stage: - build tags: - aws-fargate script: - echo "www.bitslovers.com" && ./configure && make && make install
Select the Runner dynamically by Tag
Also, it’s possible to make our pipeline even more dynamic by applying variables instead of hardcoding the values. Like the example below:
TAG_RUNNER: aws-fargate job: tags: - linux-large - $TAG_RUNNER script: - echo "Let's build our project!"
So, we can manipulate the $TAG_RUNNER value using scripts and then dynamically select the Runner we need.
Gitlab Runner Tags provide us the flexibility to manage our Runner, and for the complex environment, they are essential features to keep control over our resources.
I hope that this post was helpful to you. So please leave a comment and follow us on social media and stay tuned for new posts.