且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以在Azure DevOps发布管道中以编程方式为变量设置可覆盖的默认值吗?

更新时间:2023-11-04 11:11:22

对话框出现时,some_var变量已经设置为一个值存储在文本文件中.

我们不支持此开箱即用功能.发布管道变量不能动态在创建发行版之前填充 some_var 值.

可能的解决方法:

您的原始目的是根据工件放置文件夹中文件的内容,以编程方式对其进行设置.因此,我假设您可能具有此版本所依赖的构建管道,而您的实际需求是:

构建管道完成后,发布管道中 some_var 默认值应设置为构建管道中的值.

您可以考虑在发行版本所依赖的构建管道的末尾添加Powershell任务,调用

整个行为是(假设我们要将Build中的buildID传递给Release中的 some_var ):

1.构建管道执行良好,其上一个Powershell任务将 some_var 更新为 some_var = 15 .

2.当我单击 Create release 按钮时,对话框弹出 some_var 变量,该变量已经设置为Build管道 15 中的值.

3.现在,由于 some_var 在发布时启用了可设置,因此我们可以在单击 Create 按钮之前轻松地对其进行修改.

希望它会有所帮助:)

I have a variable called some_var in an Azure DevOps release pipeline. I'd like to set the default at release time. But I want to set it programmatically based on the contents of a file in the artifact drop folder. But I still want the user to be able to overwrite the dynamically set value at the time they're creating the release.

So the end-user behavior would be that they (1) navigate to the Release and (2) click "Create New". The dialog comes up with the some_var variable already set to a value stored in a text file. But, because the variable is set to be settable at runtime, they can also modify the variable value before they click the button to create the release.

Is there any way I can dynamically populate (before the release is created) the some_var value and still make it editable by the person creating the release at crate-time.

The dialog comes up with the some_var variable already set to a value stored in a text file.

We don't support this out-of-box feature. The release pipeline variable can't dynamically populate the some_var value before the release is created.

Possible workaround:

Your original purpose is to set it programmatically based on the contents of a file in the artifact drop folder. So I assume you may have a build pipeline which this release depends on, and your actual need is to:

Once the build pipeline is finished, the default value of some_var in release pipeline should set as the value from build pipeline.

You can consider adding a powershell task in the end of build pipeline that release depends on, calling the Definitions-Update rest api in ps script to set the default value of some_var in Release pipeline depending on content of Build pipeline. Similar issue you can check this one.

And if the pipeline variable some_var is settable at release time:

The whole behavior would be (assuming we want to pass the buildID in Build to the some_var in Release):

1.The build pipeline executes well, its last Powershell task updates the some_var to some_var = 15.

2.When I click the Create release button, the dialog comes up with some_var variable already set to a value from Build pipeline 15.

3.Now, because the some_var enables settable at release time, we can easily modify it before clicking the Create button.

Hope it helps :)