简体   繁体   English

Azure 发布管道 - python 脚本上的环境变量

[英]Azure Release Pipeline - Environment variables on python script

Lately I've been requested to run a python script on my Azure Release Pipeline.最近我被要求在我的 Azure 发布管道上运行 python 脚本。

This script needs some environment variables for being executed, as I've seen that in the build pipeline, the task include a "env" part where I can set environment variables.该脚本需要一些环境变量才能执行,正如我在构建管道中看到的那样,该任务包括一个“env”部分,我可以在其中设置环境变量。 The thing is that in the release pipeline I cannot find anything related to env问题是在发布管道中我找不到与 env 相关的任何内容

Azure Release Pipeline Python task Azure 发布管道 Python 任务

I've researching in all the documentation and previous questions but I cannot find anything else related with this.我已经研究了所有文档和以前的问题,但找不到与此相关的任何其他内容。 Is there any way to set environment variables here?有没有办法在这里设置环境变量?

The only I need is that the variables declared on the variable group linked to the pipeline can be readed and used in the python script.我唯一需要的是,在链接到管道的变量组上声明的变量可以在 python 脚本中读取和使用。

Thank you!谢谢!

You could not define Environment Variables directly in Python Script task in Azure Release Pipeline.您不能直接在 Azure 发布管道中的 Python 脚本任务中定义环境变量。

As a work around, you could use Arguments to define Variables used in this task.作为一种变通方法,您可以使用 Arguments 来定义此任务中使用的变量。

Here is a sample:这是一个示例:

1.Link your Python Script task to the Target Variable Group. 1.将您的 Python 脚本任务链接到目标变量组。 在此处输入图像描述

2.Add arguments to link to variables 2.添加arguments链接到变量在此处输入图像描述 在此处输入图像描述

In release pipelines you should have a variables option at the top.在发布管道中,您应该在顶部有一个变量选项。 Click this and under Pipeline Variables you'll see two columns name and value.单击它,在 Pipeline Variables 下,您将看到两列名称和值。 Enter the variables here then you can access them using os in python with the following:在此处输入变量,然后您可以使用 python 中的 os 访问它们:

import os
os.environ['name']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM