Make sure, pipelines run sequential in gitlab

Viewed 561

of course I am aware, that single jobs run in sequence FIFO if these jobs are pointing to a single runner, so they fave to wait.

That is fine.

For a test environment, where we can only deploy & test one version at a time, we need not only single jobs to be queryed, but whole pipelines.

To be clear: If we have Job_Deploy & Job_Test which are Part of a Pipeline Pipeline, we need to wait for the whole pipeline to be done.

By now we have the scenarion, that the sequence can possible not be in order:

Job_Deploy1, Job_Deploy2, Job_Test2, Job_Test1 may be the case.

But we need it strict FIFO

Pipeline1(Job_Deploy1, Job_Test1), Pipeline(Job_Deploy2, Job_Test2)

How can we achieve this?

Why do we seem to be alone with this requirement? Do we have any wrong perceptions here? Is it best practice? If not: why?

Best regards

1 Answers

It seems like i misread the question and my initial answer is not applicable, i leave it at the end.


Right answer:

Use resource_group to create a resource group that ensures a job is mutually exclusive across different pipelines for the same project.

There are are so called resource_groups which you can use to force a certain order. and which ensures that jobs only run after each other even if they are in separate pipelines.

https://docs.gitlab.com/ee/ci/yaml/#resource_group


Wrong answer:

What you are looking for is the needs directive.

It offers you the possibility to express job dependencies within your ci file.

Something like

deploy1:
  script: echo "deploy 1"

test1:
  script: echo "test 1"
  needs:
    - deploy1

This means that test1 even if it is in the same stage, will not start as long as deploy1 has finished. Furthermore, you could also add needs: [] to deploy1 to start it immediately even if it is in a later stage. needs is powerful and allows you to work outside the stage boundaries.

Take a look at https://docs.gitlab.com/ee/ci/yaml/#needs

Related