我有一个场景,我需要使用 Pipeline 从 Azure Repos 运行 Python 脚本,并且我有需要存储在 Azure Pipeline 变量中的 API 身份验证密钥。密钥已存储,但问题是如何在 Python 脚本中使用它,以及如何在执行时从 Azure 变量中提取变量。我尝试过搜索示例,但除了 Microsoft Docs 上的 bash 和 PowerShell 之外,关于 Python 的了解不多。
我如何将其添加到此处?这不是内联脚本,而是 Azure Repos 中的脚本。我正在从 Azure Pipeline 运行此脚本。
Python 脚本的屏幕截图
非常感谢任何示例!
谢谢!
I have a scenario where I need to run Python script from the Azure Repos with Pipeline and I have API auth key that I need to store in Azure Pipeline variables. The key is stored, but the question is how to use it in Python script and when it's executing it pulls the variable from the Azure Variables. I have tried to search for example, but not really much about Python except bash and PowerShell on Microsoft Docs.
How do I add it here? This is not an inline script, but the one that's in Azure Repos. I am running this script from the Azure Pipeline.
screenshot of the python script
Any example is much appreciated!
Thanks!
发布评论
评论(1)
您可以获得 运行时使用宏语法的变量值 - 例如
$(ApiAuthKey)
- 并通过参数
参数,所以在你的管道中:在 python 中,你 使用列表
sys.argv
访问参数:You can get the variable value at runtime with macro syntax - for example
$(ApiAuthKey)
- and pass it via thearguments
parameter, so in your pipeline:In python you access the arguments with the list
sys.argv
: