【问题标题】:TFS 2015.3 custom build step not sending variables to the scriptTFS 2015.3 自定义构建步骤未将变量发送到脚本
【发布时间】:2016-12-20 17:19:39
【问题描述】:

我已密切遵循 hereherehere 的设计指南,但我不断收到此 PowerShell 错误:

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

相关配置数据如下。

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

这里可能出了什么问题?这是一个非常简单的架构——没有什么可破坏的。但很明显,某些事情已经做到了这一点。


来自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"
  }
}

来自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
)

【问题讨论】:

  • @ScottLangham:你对这个版本做了什么改动?请参阅Task versions 上的特定文档,其中指出:“当发布新的次要版本(例如,1.2 到 1.3)时,您的构建或发布将自动使用新版本。但是,如果新的主要版本已发布(例如 2.0),您的构建或发布将继续使用您指定的主要版本,直到您编辑定义并手动更改为新的主要版本。"
  • 我尝试了版本中的次要和补丁字段。
  • @ScottLangham — 我暂时将自定义任务放在一边,但如果我继续努力并找到解决方法,我会将其发送给您。
  • @InteXX 非常感谢您的帮助,不过我现在很好.. 我发布的答案对我有用。
  • @ScottLangham — 这看起来像是一种新语法。我必须牢记这一点。

标签: powershell tfs tfsbuild tfs-2015


【解决方案1】:

显然我没有密切关注...我错过了this page 上的警告:

警告词

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

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

一旦我把这一切理顺了,一切都很好。

【讨论】:

    【解决方案2】:

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

    [CmdletBinding()]
    param()
    
    $myParam = Get-VstsInput -Name myParam -Require
    

    【讨论】:

      猜你喜欢
      • 2018-04-27
      • 2016-10-29
      • 2023-04-03
      • 1970-01-01
      • 2017-06-23
      • 2016-09-02
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      相关资源
      最近更新 更多