0

我正在尝试创建自定义构建任务以在管道执行期间检索常见的 PowerShell 脚本。内联脚本非常简单,在通用 PowerShell 任务中运行时运行良好:

$Token = $env:SYSTEM_ACCESSTOKEN
$Path = $env:BUILD_STAGINGDIRECTORY
$Uri = $env:BUILD_REPOSITORY_URI

$Parts = $Uri -split "/"
$Parts[2] = $Token + "@" + $Parts[2]
$Parts[6] = "PipelineScripts"

$Uri = $Parts -join "/"
$Path = "$Path\Scripts"

If (!(Test-Path $Path)) {
  New-Item -ItemType Directory $Path
}

Set-Location $Path

git clone $Uri .

这是我的自定义任务 JSON:

{
  "id":"B9780285-58E8-48C4-8281-4267DDC9AC90",
  "name":"GetPipelineScripts",
  "friendlyName":"Get Pipeline Scripts",
  "description":"This task retrieves common PowerShell scripts during execution of a build pipeline.",
  "helpMarkDown":"",
  "category":"Package",
  "author":"Author",
  "version":{
    "Major":1,
    "Minor":0,
    "Patch":6
  },
  "minimumAgentVersion":"2.131.0",
  "instanceNameFormat":"Get Pipeline Scripts",
  "inputs":[
    {
      "targetType":"inline",
      "script":"$Token = $env:SYSTEM_ACCESSTOKEN\n$Path = $env:BUILD_STAGINGDIRECTORY\n$Uri = $env:BUILD_REPOSITORY_URI\n\n$Parts = $Uri -split \"/\"\n$Parts[2] = $Token + \"@\" + $Parts[2]\n$Parts[6] = \"PipelineScripts\"\n\n$Uri = $Parts -join \"/\"\n$Path = \"$Path\\Scripts\"\n\nIf (!(Test-Path $Path)) {\n  New-Item -ItemType Directory $Path\n}\n\nSet-Location $Path\n\ngit clone $Uri .\n",
      "errorActionPreference":"stop",
      "failOnStderr":"false",
      "ignoreLASTEXITCODE":"false",
      "pwsh":"false"
    }
  ],
  "execution":{
    "PowerShell":{
      "argumentFormat":"",
      "workingDirectory":""
    }
  }
}

它出现在可用任务列表中:

在此处输入图像描述

...我可以将它添加到管道中:

在此处输入图像描述

...但是当我尝试保存管道时,出现错误:

Value cannot be null.
Parameter name: key

在此处输入图像描述

这是非常出乎意料的。在我的任务 JSON 中没有一个字段或属性名为key. 我一定在某处遗漏了什么。我从这里得到了示例 JSON 。

搜索会找到类似错误消息的解决方案,自定义构建任务除外。

我应该如何修改这个任务,以便我可以成功地保存它并在管道中运行它?

4

0 回答 0