Gitlab CI :- How to create the Shared Runner in Gitlab which does not depend on the any system?

Viewed 20534

I have study about the Gitlab Runner which are two types one is Custom Runner and another one is Shared Runner.

I have used the Custom Runner like docker in the Gitlab for creating the apk of the Android. And It works fine and create the build which desired. But in this way i am getting one problem is that it depends on my system means when my system is on then my Custom Runner works fine but when my system become off then Gitlab fail to perform operation because it depends on my system runner.

I have read about the Shared Runner which does not depend on anything and perform the operation. I have read the documentation but did not get the proper way to implement it .

Please check my .gitlab-ci.yml file below

image: jangrewe/gitlab-ci-android

stages:
  - build

before_script:
  - export GRADLE_USER_HOME=$(pwd)/.gradle
  - chmod +x ./gradlew

cache:
  key: ${CI_PROJECT_ID}
  paths:
    - .gradle/

build:
  stage: build
  tags:
    - dev-ci
  script:
    - ./gradlew assembleDevelopment assembleProduction assembleStaging
  artifacts:
    paths:
      - app/build/outputs/

Please help me on the Shared Runner of the Gitlab

1 Answers

Steps to register a Shared Runner:

Pre-requisite: Gitlab-Runner should have been installed. Follow this document for Installing Runner

  • Login to Gitlab. Go to Admin Area >> Overview >> Runners >> Set up a shared Runner manually

enter image description here

  • Login to the server where runner is installed, either with root user or the user with which you have installed runner (say gitlab-runner). Here, we are registering the runner using root user. Run the below command:

    gitlab-runner register

  • Fill the following details according to your setup:

    • Please enter the gitlab-ci coordinator URL: https://example.com/gitlab/

      (Look for the url in the gitlab under Set up a shared Runner manually)

    • Please enter the gitlab-ci token for this runner: jiRS-3KxGaEdkLo6tToZ

      (Look for the token in the gitlab under Set up a shared Runner manually )

    • Please enter the gitlab-ci description for this runner: my-first-shred-runner

      (Enter any name for the runner)

    • Please enter the gitlab-ci tags for this runner (comma separated): ci-shared,ci-task

      (Enter any tags you want to associate with the runner)

    • Please enter the executor: docker-ssh, parallels, virtualbox, docker+machine, kubernetes, custom, docker, docker-ssh+machine, shell, ssh: shell

      (Enter the executor you need the runner to use, depending on choice of executor you will get other options to fill. Please go through documents of executors )

Now, you can see the message runner has been registered.

enter image description here

You can verify the same in the Gitlab. Go to Gitlab, Admin Area >> Overview >> Runners >> Set up a shared Runner manually and you can see the runner has been registered with name my-first-shred-runner

enter image description here

Steps to enable Shared Runner for a project in Gitlab:

  1. Go to a Project in Gitlab.
  2. Then, in the project page, Settings >> CI/CD >> Runners >> Shared Runners
  3. Then, click on Enable shared runners. Now, you can use the shared runner for Gitlab CI/CD.
  4. Use the tags associated with shared runner in .gitlab-ci.yml, so that the jobs will run using shared runner.

enter image description here

Change the tags in .gitlab-ci.yml

image: jangrewe/gitlab-ci-android

stages:
  - build

before_script:
  - export GRADLE_USER_HOME=$(pwd)/.gradle
  - chmod +x ./gradlew

cache:
  key: ${CI_PROJECT_ID}
  paths:
    - .gradle/

build:
  stage: build
  tags:
    - ci-shared
  script:
    - ./gradlew assembleDevelopment assembleProduction assembleStaging
  artifacts:
    paths:
      - app/build/outputs/

Steps to register Specific Runner:

  1. Login to Gitlab. Go to the Project and then Settings >> CI/CD >> Runners >> Set up a specific Runner manually
  2. Next, follow the same steps from step 2 as given above for Registering Shared Runner

enter image description here

Related