具有未知数量输入的 Azure 管道自定义任务 [英] Azure pipeline custom task with an unknown number of inputs

本文介绍了具有未知数量输入的 Azure 管道自定义任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 TypeScript 为 Azure 管道创建自定义任务.

I am creating a custom task for Azure pipeline using TypeScript.

我定义了一个 filePath 输入:

I have defined a filePath input:

{
    "name": "myFile",
    "label": "file to read",
    "type": "filePath",
    "required": true,
    "groupName": "files",
    "helpMarkDown": "file to read",
    "defaultValue": "",
    "visibleRule": "getFile = true"
},

用户应该能够在任务中定义未知数量的路径.

The user is supposed to be able to define an unknown number of paths in the task.

  1. 有没有办法在任务中以某种方式动态生成输入,如果用户浏览路径,gui 将显示另一个 filePath 输入?如果有这样的选项,我该如何迭代它们并将所有文件下载到管道中?

  1. Is there a way to somehow generate the input dynamically in the task in a way that if a user browse a path, the gui will present another filePath input? If there is an option like that, how can I also iterate over them and download all the files to the pipeline?

1 的替代方案 - 我可以有一个简单的字符串输入,我可以在其中指示用户输入多个路径.在这种情况下,用户如何在没有 filePath 输入为您提供的浏览按钮的帮助下提取存储库中文件的路径?

An alternative to 1 - I can have a simple string input in which I instruct the user to enter several paths. In this scenario how does a user extract the path of the file in the repo without the help of the browse button that the filePath input gives you?

推荐答案

大多数任务都提供多行文本框(可选择调整大小),您可以在 task.json 中设置:

Most tasks offer a multi-line textbox (optionally resizable), you can set this in the task.json:

{
      "name": "patternManifest",
      "type": "multiLine",
      "properties": {
        "resizable": true,
        "rows": "1"
      },
      "label": "Manifest file(s)",
      "defaultValue": "vss-extension.json",
      "required": false,
      "helpMarkDown": "Specify the pattern for manifest files. One file per line."
    },

然后在任务本身中使用 tl.getDelimitedInput() 并传入要支持的分隔符,在此任务中我要求他们使用换行符 \n:

Then in the task itself you use the tl.getDelimitedInput() and pass in the delimiters you want to support, in this task I require them to use newlines \n:

const globsManifest = tl.getDelimitedInput("patternManifest", "\n", false);

tasklibrary 也支持通配符匹配,这样人们可以将 ***? 添加到他们的输入和任务会将这些解析为实际文件,然后使用 tl.findMatch() 选项.

The tasklibrary has support for wildcard matching as well, that way people can add *, ** and ? to their inputs and the task will resolve these to actual files, then use the tl.findMatch() option.

            if (vsixFilePattern.indexOf("*") >= 0 || vsixFilePattern.indexOf("?") >= 0) {
                tl.debug("Pattern found in vsixFile parameter.");
                matchingVsixFile = tl.findMatch(process.cwd(), vsixFilePattern);
            }
            else {
                tl.debug("No pattern found in vsixFile parameter.");
                matchingVsixFile = [vsixFilePattern];
            }

默认情况下路径是相对的,并使用任务的工作目录.当没有指定时,工作目录取决于任务的上下文(构建与部署管道):

The paths are relative by default and use the task's workingdirectory. When none is specified the working directory depends on the context of the task (build vs deploy pipeline):

  "execution": {
    "PowerShell3": {
      "target": "$(currentDirectory)\\TfvcCheckin.v3.ps1",
      "workingDirectory": "$(Build.SourcesDirectory)"
    }
  }

用户总是可以输入绝对路径而不是相对路径.而且他们总是可以添加诸如 $(Build.SourcesDirectory)\a\b\c 之类的变量来根路径到预定义位置.

The user can always enter an absolute path instead of a relative one. And they can always add variables like $(Build.SourcesDirectory)\a\b\c to root the path to a predefined location.

这篇关于具有未知数量输入的 Azure 管道自定义任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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