Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.