'Is it possible to "lock" group of jobs across multiple gitlab pipelines

I have multiple jobs working with a single external resource (Server). The first job deploys the app to the environment, the second execute tests at this environment, third execute integration tests at this environment.

I know there is Resource group option. But it locks only jobs. If two pipelines run concurrently I need to execute job1, job2, job3 from the first pipeline, and only when the first pipeline release resource - the second pipeline can launch jobs1-3. Is there a way to achieve this? There are other jobs in the pipeline - they should work concurrently.



Solution 1:[1]

Setup a dedicated runner for the jobs1-3.

  1. Setup a new runner with an unique tag eg 'jobs-1-2-3' and set the option concurrent to 1.

  2. Add the unique tag eg 'jobs-1-2-3' to the jobs in question.

    job1:
      tags:
        - jobs-1-2-3
    job2:
      tags:
        - jobs-1-2-3
    job3:
      tags:
        - jobs-1-2-3
    

IMHO this is less effort and more reliable.

Solution 2:[2]

I think it can be implemented through the needs and resource_group keywords and the gitlab API.

Every job receives the pipeline id to which it belongs as a predefined-variable. If you use the gitlab api, you can see the status of other jobs in the pipeline. If you can use this status, needs and resource_group keywords I think you can achieve what you intended. See the description of below code and its comments for more details.

stages:
  - ready
  - build

job1:
  stage: build
  needs: [starting_signal]
  script: 
    - sleep 10 && echo "job1"
job2:
  stage: build
  needs: [starting_signal]
  script:
    - sleep 20 && echo "job2"
job3:
  stage: build
  needs: [starting_signal]
  script:
    - sleep 30 && echo "job3"

starting_signal:
  stage: ready
  script:
    - # TODO: You need to implement it using the GitLab API.
    - # The starting condition for "job1-3" is
    - # that this `starting_signal` job finished successfully.
    - # And the condition that ends with the success of this job
    - # is that `traffic_light` becomes running.

traffic_light: 
  stage: ready
  resource_group: traffic_light
  script:
    - # TODO: You need to implement it using the GitLab API.
    - # The end condition for `traffic_light` is
    - # the end of job1-3 execution.
    - # In other words, this job must be checked and waited
    - # through gitlab api until job 1,2,3 is finished.
    - # Since this job locks the execution of a `traffic_light` job
    - # in another pipeline, the `starting_signal` job in another 
    - # pipeline does not succeed.

(I didn't test it myself, so this method needs a review.)

Referenecs:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RiWe
Solution 2