Makefile:设置环境变量以供将来在构建步骤中使用 [英] Makefile: Set environment variable for future use as part of a build step

查看:60
本文介绍了Makefile:设置环境变量以供将来在构建步骤中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将环境变量设置为构建步骤的一部分,然后由后续构建步骤使用?

Is it possible to set an environment variable as part of a build step that is then consumed by a subsequent build step?

我要完成的工作:

  1. 一个构建步骤将登录到秘密服务器,并获取要求其构建的特定构建目标的登录凭据.

  1. One build steps logs into a secrets server and obtains login credentials for the specific build target it's been asked to build.

稍后的构建步骤将使用这些凭据将其部署到特定的目标环境.

A later build step uses those credentials to deploy to a specific targeted environment.

是否有一种方法可以从步骤1中导出一个环境变量,该变量随后将在步骤2中可用?

Is there a way to export an environment variable from step 1 that would then be available in step 2?

推荐答案

不,这是不可能的.这是所有POSIX系统中流程的基本方面,一个流程无法修改其父(或同级)环境.因此,当一个进程(无论如何调用)获得这些值时,就无法将它们提升"到其父级环境中.

No, that is not possible. It's a fundamental aspect of processes in all POSIX systems that one process cannot modify the environment of its parent (or siblings). So when a process (regardless of how it's invoked) obtains those values it cannot "promote" them up into the environment of its parent.

该进程可以将它们写入一个文件,以供以后的进程读取.

The process could write them to a file that a later process can read.

或者,该流程可以将它们打印出来,而父流程可以捕获输出并记住它,然后将其解析到自己的环境中.在GNU中,它可能类似于:

Alternatively, the process could print them out and the parent process could capture the output and remember it, and parse it into its own environment. In GNU make that could be something like:

creds := $(shell get-my-credentials)

没有更多有关要求和限制的详细信息,这很难弄清楚.

Without more details of the requirements and restrictions it's hard to be precise.

这篇关于Makefile:设置环境变量以供将来在构建步骤中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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