Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
859 views
in Technique[技术] by (71.8m points)

typescript - Azure pipeline custom task with an unknown number of inputs

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

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. 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?

  2. 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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."
    },

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 :

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

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)"
    }
  }

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...