在Azure devops中跨构建管道共享变量 [英] Share variables across build pipelines in Azure devops

查看:72
本文介绍了在Azure devops中跨构建管道共享变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的azure devops项目中有2条构建管道,一条用于构建源代码,另一条用于进行设置.我希望将编译代码的第一个管道生成的内部版本号传递到创建安装文件的下一个管道,因为我希望安装文件采用相同的版本,因此我添加了一个变量组,该变量组的变量名为sharedBuildCounter .

I have 2 build pipelines in my azure devops project, one for building source code and the other one is for making the setup. I want the build number generated by the first pipeline that compiles code to be passed to the next pipeline which creates the setup file because i want the setup file to take the same version, so I added a variable group with a variable called sharedBuildCounter.

但是当我使用这样的日志记录命令(在PowerShell任务中使用)在第一个管道中设置 sharedBuildCounter 时,内部版本号:

But when I set sharedBuildCounter the build number in the first pipeline using logging command like this(used inside PowerShell task):

写入主机"## vso [task.setvariable variable = variable_name;] new_value"

该变量确实采用了新值,并且我能够使用另一行带有一行的PowerShell任务来输出新值:

The variable indeed takes the new value and I am able to output the new value using another PowerShell task with one line:

写入主机$(SharedBuildCounter)

当我运行下一个建立设置的管道时,我发现 sharedBuildCounter 被重新设置为默认的空值.

And when I run the next pipeline that builds the setup, I find that sharedBuildCounter is being re-set to the default empty value.

注意::我发现一些线程建议使用API​​ rest调用来更改变量值,但是在使用管道变量(而非变量组)的情况下,它似乎并未包括特定的管道名称.

Notice: I found threads that suggests using API rest calls to change variable values, but it don't seem to include a specific pipeline name in case of using pipeline variables(not variable groups).

推荐答案

变量组将有助于在构建和发布管道之间共享静态值.

Variable groups will help to share static values across builds and releases pipeline.

您需要的是一种将变量从一个管道传递到另一个管道的方法.恐怕要说这不是官方的方法.

What you need is a way to pass variables from one pipeline to another. I'm afraid to say the is no official way to do this.

作为解决方法,您可以更新变量组中变量的值.有多种处理方式,Rest API,powershell,3rd-party扩展.详细方法,请参考此问题的答案:如何使用Azure Devops构建定义增加/更新变量组值?

As a workaround you could update the value of your variables inside your variable group. There are multiple ways to handle this, Rest API, powershell, 3rd-party extension. Detail ways please refer answers in this question: How to Increase/Update Variable Group value using Azure Devops Build Definition?

如果要在管道中获取变量的值.由于您已使用logging命令来更新该变量.

If you want to get the value of variable in the pipeline. Since you have used logging command to update that variable.

您需要使用

You need to use Rest API to get that particular build log to fetch related info.

这篇关于在Azure devops中跨构建管道共享变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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