SBKDeveloper
SBKDeveloper

Reputation: 693

Dynamically Including/Excluding Jobs in Gitlab Pipeline

I have a Pipeline that has a few stages: detect, test, build, deploy

The detect stage detects the type of application and the test and build stages have jobs that are included or excluded based on what is computed in detect. The detect stage writes it's value to a environment variable called BUILD_MODE.

I am using rules like so:

ng-build:
  extends:
    - '.ng/job/build'
  stage: build
  rules:
    - if: $BUILD_MODE == "ANGULAR"
      when: always

npm-build:
  extends:
    - '.npm/job/build'
  stage: build
  rules:
    - if: $BUILD_MODE == "NPM"
      when: always

The problem with this is that the BUILD_MODE variable is evaluated statically when the pipeline is created not after the detect stage runs so the above never works unless I set the variable explicitly in the top level YML file like so:

variables:
 BUILD_MODE: "ANGULAR"

What is the best way to solve this problem? The summary of what I want to do is evaluate some condition, either set the stages dynamically or set the variable itself before the stages in the Pipleline are created so they will be created with the rules evaluated correctly.

Upvotes: 4

Views: 2553

Answers (1)

danielnelz
danielnelz

Reputation: 5136

You could take a look at dynamic child-pipelines. Maybe you could solve your problem by dynamically creating your npm/ng build jobs.

Upvotes: 4

Related Questions