Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait a GitLab job if the same job is running in the previous pipeline?

We have a requirement where the deploy job in a pipeline should wait if a previous pipeline has the same deploy job in running state. We are facing a concurrency issue due to this. Example:

  • Old Pipeline in running state due to a commit > Job Name DEV Deployment -> Clean data and deploy
  • New Pipeline in running state due to a new commit > Job Name DEV Deployment --> Now this clean data will impact the previous pipeline deployment.

We want to wait for the new pipeline specific jobs until the previous pipeline with the same job name is not finished.

DO we have any solution for this in GitLab?

I have a workaround for this to handle using a before_script with pipeline API. Steps which I am performing to handle this:

  1. For the new pipeline first check the current pipeline ID.
  2. Then check the previous pipelines which are not equal to the current pipeline ID and the status is running or pending.
  3. Then fetch the current pipeline deployment job name.
  4. Then check the previous running pipeline with the same job name.
  5. If yes then wait else skip and move for new deployments.

Any generic solution without handling via the script will be highly appreciated.

like image 818
Akash Kashyap Avatar asked Oct 24 '25 19:10

Akash Kashyap


1 Answers

We can use resource_group in the yaml to wait for a specific jobs. Example to add resource_group:

DEV Deployment:
  stage: deploy
  resource_group: my_deploy
  script:
    - echo "Demo Test" >> README.md
    - sleep 200

For details please check https://docs.gitlab.com/ee/ci/resource_groups/

like image 189
Akash Kashyap Avatar answered Oct 27 '25 01:10

Akash Kashyap



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!