任务A如何在同一个任务组(TG)中创建新的构建变量以供任务B使用,而又不将其暴露在TG之外? [英] How can Task A create a new build variables to be consumed by task B in the same Task Group (TG) without exposing it outside of the TG?

查看:77
本文介绍了任务A如何在同一个任务组(TG)中创建新的构建变量以供任务B使用,而又不将其暴露在TG之外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个任务组,其中有两个任务:

I have a Task Group with two tasks:

  1. 设置BinLogFlag
  2. 编译解决方案

第一个任务实际上是另一个TG,如果请求二进制日志,则该TG设置BinLogFlag ="/bl:...".它基本上运行以下Powershell代码:

The first task is actually another TG that sets BinLogFlag="/bl:...", if binary log is requested. It basically run the following Powershell code:

"##vso[task.setvariable variable=BinLogFlag]..."

现在编译解决方案就是带有以下命令行的MSBuild任务:

Now Compile Solution is simply the MSBuild task with the following command line:

/m /v:m $(BinLogFlag)

因此,回顾一下-设置BinLogFlag 创建了构建变量BinLogFlag,编译解决方案使用了它.当然,如果BinLogFlag为空,则不会生成二进制日志.

So, to recap - Set BinLogFlag creates the build variable BinLogFlag and Compile Solution uses it. Of course, if BinLogFlag is empty, then no binary log is generated.

问题在于,我将$(BinLogFlag)添加到命令行的那一刻,Azure DevOps将其添加到我开发的TG的参数中:

The problem is that the moment I add $(BinLogFlag) to the command line, Azure DevOps adds it to the parameters of the TG I develop:

但这是内部实现细节.我不想暴露它.我当前的解决方法很脆弱-我先更新/生成Directory.Build.rsp文件,然后再进行编译,然后再删除/还原.

But it is an internal implementation detail. I do not want it exposed. My current workaround is fragile - I updated/generate Directory.Build.rsp file before compiling and delete/restore it afterwards.

我一点都不喜欢它. 编译解决方案是否可以使用由 Set BinLogFlag 创建的BinLogFlag构建变量,而不会将其暴露为父任务组的另一个参数?

I do not like it at all. Is it possible for Compile Solution to use the BinLogFlag build variable created by Set BinLogFlag without exposing it as yet another parameter of the parent Task Group?

推荐答案

编译解决方案是否可以使用由Set BinLogFlag创建的BinLogFlag构建变量,而不会将其暴露为父任务组的另一个参数?

Is it possible for Compile Solution to use the BinLogFlag build variable created by Set BinLogFlag without exposing it as yet another parameter of the parent Task Group?

答案是肯定的.

创建任务组后,任务组具有一项功能:导出:

There is a feature for Task Group: Export after we create the task group:

导出它,您将获得.json文件,并使用记事本或Visual Studio打开它,您将获得有关参数的以下代码段:

Export it, you will get the .json file and open it with notepad or Visual Studio, you will get following code segment about parameter :

  "iconUrl": "https://cdn.vsassets.io/v/M154_20190723.10/_content/icon-meta-task.png",
  "friendlyName": "TestTG",
  "description": "",
  "category": "Build",
  "definitionType": "metaTask",
  "author": "YourCount",
  "demands": [],
  "groups": [],
  "inputs": [
    {
      "aliases": [],
      "options": {},
      "properties": {},
      "name": "",
      "label": "",
      "defaultValue": "",
      "required": true,
      "type": "string",
      "helpMarkDown": "",
      "groupName": ""
    }
  ],
  "satisfies": [],

然后,我们删除了[]输入中的内容,因此它看起来像:

Then, we delete the content in the inputs to [], so it looks like:

  "groups": [],
  "inputs": [],
  "satisfies": [],

最后,我们将此.json导入回任务组,并使用新名称Set BinLogFlag V2重命名.

Finally, we import this .json back to the task group and rename it with a new name Set BinLogFlag V2.

当我们将此任务组添加到管道中以创建另一个任务组编译解决方案时,由集 BinLogFlag 创建的BinLogFlag构建变量将不暴露:

When we add this task group to the pipeline to create the another task group Compile Solution, the BinLogFlag build variable created by set BinLogFlag will not be exposed:

在您的演示中,我使用命令行任务而不是MSBuild来测试变量BinLogFlag的值是否可以正确传递.它可以很好地作为测试.

I use the command line task instead of MSBuild in your demo to test if the value of the variable BinLogFlag can be passed correctly. And it works fine as test.

希望这会有所帮助.

这篇关于任务A如何在同一个任务组(TG)中创建新的构建变量以供任务B使用,而又不将其暴露在TG之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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