简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM