如何在 gitlab ci/cd 中 pipeline job 之间传递变量


pipeline 中不同 job 默认是无法传递变量的,但是我们可以通过 artifacts 功能实现传递,具体看实例

build:
  stage: build
  script:
    - echo "BUILD_VARIABLE=value_from_build_job" >> build.env
  artifacts:
    reports:
      dotenv: build.env

deploy:
  stage: deploy
  script:
    - env
    - echo "$BUILD_VARIABLE"  # Output is: 'value_from_build_job'

参考官方文档:https://docs.gitlab.com/ee/ci/variables/#pass-an-environment-variable-to-another-job

artifacts 这种传递变量的方法还可用于多项目 pipeline、父子 pipeline 中,具体参考:https://docs.gitlab.com/14.7/ee/ci/pipelines/multi_project_pipelines.html#pass-cicd-variables-to-a-downstream-pipeline-by-using-variable-inheritance


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM