Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab CI/CD: pass job environment variables to shell script

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?

like image 800
Andreas Hunter Avatar asked Aug 11 '26 12:08

Andreas Hunter


1 Answers

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.

like image 177
trammik Avatar answered Aug 14 '26 11:08

trammik