Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS 2015.3 custom build step not sending variables to the script

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

Cannot process command because of one or more missing mandatory parameters: 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.

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:

"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:

[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
)
like image 652
InteXX Avatar asked Aug 14 '16 04:08

InteXX


2 Answers

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.

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.

like image 196
InteXX Avatar answered Nov 11 '22 19:11

InteXX


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.

[CmdletBinding()]
param()

$myParam = Get-VstsInput -Name myParam -Require
like image 43
Scott Langham Avatar answered Nov 11 '22 21:11

Scott Langham