TFS 2015.3自定义构建步骤不向脚本发送变量

时间:2021-06-05 00:35:34

I've followed closely the design guidance found here, here and here, but I keep getting this PowerShell error:

我已经密切关注此处,此处和此处的设计指南,但我不断收到此PowerShell错误:

Cannot process command because of one or more missing mandatory parameters: SourcePath FilePattern BuildRegex.

由于缺少一个或多个必需参数,无法处理命令:SourcePath FilePattern BuildRegex。

The relevant config data is below.

相关配置数据如下。

I've checked and double-checked to make sure that the variables are present in my task.json file. I've also looked at the config for other working tasks (e.g. VSBuild) and there's no significant difference in the variable declaration and PowerShell execution syntax.

我已经检查并仔细检查以确保我的task.json文件中存在变量。我还查看了其他工作任务的配置(例如VSBuild),并且变量声明和PowerShell执行语法没有显着差异。

What could be going wrong here? This is a very simple architecture—there's not much to break. But clearly something has done just that.

这可能会出错?这是一个非常简单的架构 - 没有什么可以打破的。但显然有些事情已经做到了。


From task.json:

来自task.json:

"inputs": [
  {
    "name": "SourcePath",
    "type": "filePath",
    "label": "Source path",
    "defaultValue": "",
    "required": true,
    "helpMarkDown": "Path in which to search for version files (like AssemblyInfo.* files). NOTE: this is case sensitive for non-Windows systems." 
  },
  {
    "name": "FilePattern",
    "type": "string",
    "label": "File pattern",
    "defaultValue": "AssemblyInfo.*",
    "required": true,
    "helpMarkDown": "File filter to replace version info. The version number pattern should exist somewhere in the file(s). Supports minimatch. NOTE: this is casese sensitive for non-Windows systems."
  },
  {
    "name": "BuildRegEx",
    "type": "string",
    "label": "Build RegEx pattern",
    "defaultValue": "\\d+\\.\\d+\\.\\d+\\.\\d+",
    "required": true,
    "helpMarkDown": "Regular Expression to extract version from build number. This is also the default replace RegEx (unless otherwise specified in Advanced settings)."
  },
  {
    "name": "BuildRegExIndex",
    "type": "string",
    "label": "Build RegEx group index",
    "defaultValue": "0",
    "required": false,
    "helpMarkDown": "Index of the group in the Build RegEx that you want to use as the version number. Leave as 0 if you have no groups.",
    "groupName": "advanced"
  },
  {
    "name": "ReplaceRegEx",
    "type": "string",
    "label": "RegEx replace pattern",
    "defaultValue": "",
    "required": false,
    "helpMarkDown": "RegEx to replace with in files. Leave blank to use the Build RegEx Pattern.",
    "groupName": "advanced"
  },
  {
    "name": "ReplacePrefix",
    "type": "string",
    "label": "Prefix for replacements",
    "defaultValue": "",
    "required": false,
    "helpMarkDown": "Prefix for the RegEx result string.",
    "groupName": "advanced"
  },
  {
    "name": "ReplaceSuffix",
    "type": "string",
    "label": "Suffix for replacements",
    "defaultValue": "",
    "required": false,
    "helpMarkDown": "Suffix for the RegEx result string.",
    "groupName": "advanced"
  },
  {
    "name": "FailIfNoMatchFound",
    "type": "boolean",
    "label": "Fail if no target match found",
    "defaultValue": "false",
    "required": false,
    "helpMarkDown": "Fail the build if no match is found for the replace RegEx in the target file(s).",
    "groupName": "advanced"
  }
],
"execution": {
  "PowerShell3": {
    "target": "VersionAssembly.ps1"
  }
}

From VersionAssembly.ps1:

从VersionAssembly.ps1:

[CmdletBinding()]
param(
  [string][Parameter(Mandatory=$True)][ValidateNotNullOrEmpty()] $SourcePath,
  [string][Parameter(Mandatory=$True)][ValidateNotNullOrEmpty()] $FilePattern,
  [string][Parameter(Mandatory=$True)][ValidateNotNullOrEmpty()] $BuildRegex,
  [string]$BuildRegexIndex,
  [string]$ReplaceRegex,
  [string]$ReplacePrefix,
  [string]$ReplaceSuffix,
  [string]$FailIfNoMatchFound,
  [string]$BuildNumber = $ENV:BUILD_BUILDNUMBER
)

2 个解决方案

#1


5  

Apparently I wasn't following closely enough... I missed the warning on this page:

显然我没有密切关注......我错过了这个页面上的警告:

Words of warning

警告的话

Tasks can be versioned, use this to your advantage. All build definitions use the latest available version of a specific task, you can’t change this behavior from the web interface, so always assume the latest version is being used.

可以对任务进行版本控制,使用它对您有利。所有构建定义都使用特定任务的最新可用版本,您无法从Web界面更改此行为,因此始终假定正在使用最新版本。

If you don’t change the version number of your task when updating it, the build agents that have previously used your task will not download the newer version because the version number is still the same. This means that if you change the behavior of your task, you should always update the version number!

如果在更新任务时未更改任务的版本号,则先前使用过您的任务的构建代理将不会下载较新版本,因为版本号仍然相同。这意味着如果您更改任务的行为,则应始终更新版本号!

Once I got that all straightened out, everything worked fine.

一旦我完全理顺了,一切都运转正常。

#2


3  

Possibly the examples accepting inputs in the param section are out of date. It appears that you now need to use the Vsts-task-lib commands from your PowerShell script to get the input parameters.

可能接受param部分输入的示例已过时。您现在需要使用PowerShell脚本中的Vsts-task-lib命令来获取输入参数。

[CmdletBinding()]
param()

$myParam = Get-VstsInput -Name myParam -Require

#1


5  

Apparently I wasn't following closely enough... I missed the warning on this page:

显然我没有密切关注......我错过了这个页面上的警告:

Words of warning

警告的话

Tasks can be versioned, use this to your advantage. All build definitions use the latest available version of a specific task, you can’t change this behavior from the web interface, so always assume the latest version is being used.

可以对任务进行版本控制,使用它对您有利。所有构建定义都使用特定任务的最新可用版本,您无法从Web界面更改此行为,因此始终假定正在使用最新版本。

If you don’t change the version number of your task when updating it, the build agents that have previously used your task will not download the newer version because the version number is still the same. This means that if you change the behavior of your task, you should always update the version number!

如果在更新任务时未更改任务的版本号,则先前使用过您的任务的构建代理将不会下载较新版本,因为版本号仍然相同。这意味着如果您更改任务的行为,则应始终更新版本号!

Once I got that all straightened out, everything worked fine.

一旦我完全理顺了,一切都运转正常。

#2


3  

Possibly the examples accepting inputs in the param section are out of date. It appears that you now need to use the Vsts-task-lib commands from your PowerShell script to get the input parameters.

可能接受param部分输入的示例已过时。您现在需要使用PowerShell脚本中的Vsts-task-lib命令来获取输入参数。

[CmdletBinding()]
param()

$myParam = Get-VstsInput -Name myParam -Require