我可以从源代码访问Bitbucket Pipelines环境变量吗? [英] Can I access Bitbucket Pipelines environment variables from my source code?
问题描述
我在Bitbucket Pipelines中将敏感数据作为环境变量使用,例如数据库凭证.有没有办法可以从源代码访问这些环境变量?我不想将这些敏感数据推送到我的存储库中.
I have my sensitive data as environment variables in Bitbucket Pipelines, e.g. database credentials. Is there a way I can access these environment variables from my source code? I do not want to push these sensitive data to my repository.
推荐答案
Bitbucket管道环境变量只是常规的环境变量.您可以按通常的方式访问它们;这取决于您使用的编程语言.
Bitbucket Pipelines environment variables are just regular environment variables. You can access them however you normally would; this depends on the programming language you are using.
例如,在Python中,您可以使用 os.getenv()
,您可以选择提供默认值,以在所需的环境变量不可用时使用.
For example, in Python you can use os.getenv()
, which lets you optionally provide a default value to use in case the desired environment variable isn't available.
如果不了解您的技术堆栈的更多信息,就不可能提供更具体的答案.
Without knowing more about your technology stack it's impossible to provide a more specific answer.
这篇关于我可以从源代码访问Bitbucket Pipelines环境变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!