Ask Your Question
0

How can an additional condition be included in the same Gitlab Pipeline rule by making use of a reference?

asked 2023-05-12 08:03:07 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-12 08:08:01 +0000

djk gravatar image

An additional condition can be included in the same Gitlab Pipeline rule by making use of a reference using the "needs" keyword.

For example, let's say we have two stages in our pipeline: "build" and "test". We want the "test" stage to only run if the "build" stage succeeds and if the branch being built is "master". We can do this by adding a reference to the "build" stage in the "test" stage using the "needs" keyword.

Here's an example:

stages:
  - build
  - test

build:
  stage: build
  script:
    - # Build script here

test:
  stage: test
  needs:
    - job: build
      branch: master
  script:
    - # Test script here

In the "test" stage, we added a "needs" keyword that references the "build" stage job and specifies a branch condition. This means that the "test" stage will only run if the "build" stage job succeeds and if the branch being built is "master".

By using references like this, we can create more complex pipeline rules with multiple conditions that need to be satisfied before a job can run.

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-05-12 08:03:07 +0000

Seen: 9 times

Last updated: May 12 '23