MrTux01
MrTux01

Reputation: 393

How should use variables?

If I add variables(build stage), the stages does not work. Where exactly am I going wrong. If remove the variables under only variables section, it runs.

build:
  stage: build
  script:
    - echo "Build is running"
  only:
    changes:
      - Dockerfile
      - requirements.txt
      - ./configs/*
    variables:
      - $BUILD == "True"

development:
  stage: development
  script:
    - echo "development"
  except:
    variables:
      - $BUILD == "False"

development_build:
  stage: development_build
  script:
    - echo "BUILD OK"
  rules:
    - if: $BUILD == "True"
      when: always

Upvotes: 1

Views: 278

Answers (1)

VonC
VonC

Reputation: 1329262

The documentation mentions

only:variables / except:variables

Use the only:variables or except:variables keywords to control when to add jobs to a pipeline, based on the status of CI/CD variables.

Keyword type: Job keyword. You can use it only as part of a job.

Possible inputs: An array of CI/CD variable expressions.

First: try and use rules:if to see if the issue persists.

job1:
  variables:
    VAR1: "variable1"
  script:
    - echo "Test variable comparison"
  rules:
    - if: $VAR1 == "variable1"

Second, try with a different variable name, in case BUILD is somehow reserved.

Check also where you have BUILD defined (is there a workflow:rules:variables section?)

Upvotes: 1

Related Questions