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

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

问题描述

在GitLab CI中是否可以将环境变量从一个阶段转移到下一个阶段?我正在寻找类似于作业工件功能,仅适用于环境变量而不是文件.

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.

推荐答案

尚无此功能,但已经有

No this feature is not here yet, but there is already an issue for this topic.

我的建议是将变量保存在文件中并缓存它们,因为这些变量将不可下载,并在作业完成时被删除. 如果您想100%确保可以手动将其删除.请参见clean_up阶段.

My suggestion would be that you are saving the variables in a files and cache them, as these will be not downloadable and will be removed on finish of the job. If you want to be 100% sure you can delete it manually. See the clean_up stage.

例如

cache:
 paths:
  - save_file

stages: 
 - job_name_1
 - job_name_2
 - clean_up

job_name_1:
 script:
  - (your_task) >> save_file

job_name_2:
 script:
  - cat save_file | do_something_with_content

clean_up:
 script:
  - rm save_file
 when: always 

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

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