在 GitLab CI 中将环境变量从一个阶段导出到下一个阶段 [英] Exporting environment variables from one stage to the next in GitLab CI

查看:31
本文介绍了在 GitLab CI 中将环境变量从一个阶段导出到下一个阶段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 GitLab CI 中export 环境变量从一个阶段到下一个阶段?我正在寻找类似于 的东西作业工件 功能,仅适用于环境变量而不是文件.

Is there a way to export environment variables from one stage to the next in GitLab CI? I'm looking for something similar to the job artifacts feature, only for environment variables instead of files.

假设我在 configure 阶段配置构建,并希望将结果存储为(秘密、受保护的)环境变量以供下一阶段使用.我可以将配置保存在文件中并将它们存储为作业工件,但我担心文件中提供的机密信息无法被所有人下载.

Let's say I'm configuring the build in a configure stage and want to store the results as (secret, protected) environment variables for the next stages to use. I could safe the configuration in files and store them as job artifacts but I'm concerned about secrets beeing made available in files than can be downloaded by everyone.

推荐答案

从 Gitlab 13 开始你可以 继承环境变量 像这样:

Since Gitlab 13 you can inherit environment variables like this:

build:
  stage: build
  script:
    - echo "BUILD_VERSION=hello" >> build.env
  artifacts:
    reports:
      dotenv: build.env

deploy:
  stage: deploy
  script:
    - echo $BUILD_VERSION # => hello
  dependencies:
    - build

注意:对于 GitLab <13.1 你应该首先在 Gitlab Rails 控制台中启用它:

Note: for GitLab < 13.1 you should enable this first in Gitlab Rails console:

Feature.enable(:ci_dependency_variables)

这篇关于在 GitLab CI 中将环境变量从一个阶段导出到下一个阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆