1

I have a rest_config.yaml file which looks loke this:

host: abcd
apiKey: abcd
secretKey: abcd

I want to import these in my .gitlab-ci.yaml file and use them as my environment variable. How do I do so?

2 Answers2

1

If your yaml file is part of the checked out repository on which the gitlab-ci.yaml pipeline operates, said pipeline can read the file in a script: section, as I illustrated here.

That script: section can set environment variables.
And you can pass variables explicitly between jobs

build:
  stage: build
  script:
  - VAR1=foo
  - VAR2=bar
  - echo export VAR1="${VAR1}" > $CI_PROJECT_DIR/variables
  - echo export VAR2="${VAR2}" >> $CI_PROJECT_DIR/variables
  artifacts:
    paths:
    - variables

test:
  stage: test
  script:
  - source $CI_PROJECT_DIR/variables
  - echo VAR1 is $VAR1
  - echo VAR2 is $VAR2
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

build: stage: build script: - VAR1=foo

  • echo export VAR2="${VAR2}" >> $CI_PROJECT_DIR/variables artifacts: paths:
    • variables

test: stage: test script:

  • source $CI_PROJECT_DIR/variables
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Ethan Jun 07 '22 at 12:08