Search code examples
gitlabgitlab-ci

Can't share .env file from first GitLab stage with jobs of second stage


I have two stages - pre and clone-data. The first stage prepares a file to be used in both jobs of the second stage.

I need to keep the exact order, data-main must go only after schema-main completion, that's why I use needs instead of dependencies (not sure it's correct).

Here is my config:

vault:
  stage: pre
  script:
    - echo SRC_DB_USER=test >> vault.env
  artifacts:
    reports:
      dotenv: vault.env
    paths:
      - vault.env

schema-main:
  needs: [vault]
  stage: clone-data
  allow_failure: true
  resource_group: clone
  script:
    - cat vault.env

data-main:
  needs: [schema-main]
  stage: clone-data
  allow_failure: true
  resource_group: clone
  script:
    - cat vault.env

The problem is the second job data-main of the clone-data doesn't find the file, I'm getting cat: vault.env: No such file or directory error.

Where is my mistake? How can I get my aim?


Solution

  • Add the vault job to needs array to get the artifact from that job.

    .
    .
    .
    data-main:
      needs: ["schema-main","vault"]
      stage: clone-data
      allow_failure: true
      resource_group: clone
      script:
        - cat vault.env