Ask Your Question
2

What is the process for defining a GitLab CI job that can rely on one of two previous jobs?

asked 2023-06-05 14:34:32 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-05 14:43:02 +0000

lakamha gravatar image

To define a GitLab CI job that can rely on one of two previous jobs, you can use the "needs" keyword in your .gitlab-ci.yml file.

Here's an example:

job1:
  script:
    - echo "This is job 1!"

job2:
  script:
    - echo "This is job 2!"

job3:
  script:
    - echo "This is job 3!"
  needs:
    - job1       # to run job3, job1 must have successfully completed
    - job2       # OR job2 must have successfully completed

In this example, job3 has the "needs" keyword, which specifies that it needs either job1 or job2 to have successfully completed before it can run. This means that if either job1 or job2 fails, job3 will not run.

You can also use logical operators to specify more complex dependencies. For example:

job3:
  script:
    - echo "This is job 3!"
  needs:
    - job1
    - job2
    - manual
    - "something_else && another_thing"

In this example, job3 needs job1, job2, a manual action, and two other jobs ("somethingelse" and "anotherthing") to have successfully completed. The use of && specifies that both "somethingelse" and "anotherthing" must pass for job3 to run.

Note that you can also use the "allow_failure" keyword to specify that a job can fail without causing the pipeline to fail. This can be useful if you have a job that is not critical to the overall success of the pipeline.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-05 14:34:32 +0000

Seen: 10 times

Last updated: Jun 05 '23