5

I have like this job in my gitlab ci cd configuration file:

jobName:
  stage: dev
  script:
    - export
    - env
    - sshpass -p $SSH_PASSWORD ssh -o StrictHostKeyChecking=no $SSH_LOGIN 'bash -s' < script.sh
  when: manual

I tried share/pass current job env vars to my custom bash script file by adding this command in my job:

- export
- env

But my jon can't access (don't see) to job env vars. How I can correctly share job all env vars to bash script?

Andreas Hunter
  • 4,504
  • 11
  • 65
  • 125

1 Answers1

2

I believe dotenv might be suitable for this.

job1:
  stage: stage1
  script:
        - export VAR=123
        - echo $VAR
        - echo "VAR=$VAR" > variables.env
  artifacts:
    reports:
      dotenv: variables.env

job2:
  stage: stage2
  script: 
        - echo $VAR

And your VAR should be available in downstream jobs.

Efren
  • 4,003
  • 4
  • 33
  • 75
trammik
  • 21
  • 2