Azure DevOps set MultiLine Row parameter - azure-devops

Is it possible to set the multiLine row parameter in the task.json file for a custom task?
{
"name": "Include",
"type": "multiLine",
"label": "Include",
"defaultValue": "#(\"*.sln\")",
"required": false,
"helpMarkDown": "example help"
}
I recocnize, that the only difference between a multiLine textbox and inline textbox (PowerShell Task) is the amount of rows:
The default amount of rows of a multiLine textbox is 2.
So it would be create to define the amount a rows in a multiLine control.

Is it possible to set the multiLine row parameter in the task.json
file for a custom task?
It's possible. Use .net core task have a textbox Path to projects:
Corresponding html see here:
Which is default rows of MultiLine type.
So I compared the source of Use .net core task and PS task here and found:
{
"name": "projects",
"type": "multiLine",
"label": "Path to project(s)",
"defaultValue": "",
"visibleRule": "command = build || command = restore || command = run || command = test || command = custom || publishWebProjects = false",
"required": false,
"helpMarkDown": "The path to the csproj file(s) to use. You can use wildcards (e.g. **/*.csproj for all .csproj files in all subfolders)."
}
and this:
{
"name": "script",
"type": "multiLine",
"label": "Script",
"visibleRule": "targetType = inline",
"required": true,
"defaultValue": "# Write your PowerShell commands here.\n\nWrite-Host \"Hello World\"\n",
"properties": {
"resizable": "true",
"rows": "10",
"maxLength": "20000"
},
"helpMarkDown": ""
}
The first script comes from dotnet task and second one comes from PS task. They both use MultiLine type.
According to the difference between these two scripts I think you can get what you want by setting the rows element in properties element. Something like this:
"properties": {
...,
"rows": "xxx",
...
}
Hope it helps and if I misunderstand anything, feel free to correct me :)

Related

How to execute a PowerShell Command from within Azure Data Factory custom activity?

I have a custom activity in Azure Data Factory, which attempts to execute the following command:
PowerShell.exe -Command "Write-Host 'Hello, world!'"
However, when I debug (run) this command from within Azure Data Factory, it runs for a long time, and finally fails.
I guess it fails because perhaps it could not locate "PowerShell.exe". How can I ensure that the ADF Custom Activity has access to PowerShell.exe?
Some sites say about specifying a package (.zip file) that contains everything needed for the exe to execute. However, since PowerShell is from Microsoft, I think it would be inappropriate to ZIP the PowerShell directory, and specify it as a package to the Custom Activity.
Please suggest as to how I can execute PowerShell command from Custom Activity of an Azure Data Factory. Thanks!
Whenever I search "Execute PowerShell from Custom Activity in Azure Data Factory", the search results are talking more about which Az PowerShell command to use to trigger start an ADF pipeline.
I saw two threads in Stackoverflow.com, where the answer just specifies to use a Custom Activity, and the answer is not specific to PowerShell command call from ADF
Here is the JSON for the task:
{
"name": "ExecutePs1CustomActivity",
"properties": {
"activities": [
{
"name": "ExecutePSScriptCustomActivity",
"type": "Custom",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"command": "PowerShell.exe -Command \"Write-Host 'Hello, world!'\"",
"referenceObjects": {
"linkedServices": [],
"datasets": []
}
},
"linkedServiceName": {
"referenceName": "Ps1CustomActivityAzureBatch",
"type": "LinkedServiceReference"
}
}
],
"annotations": []
}
}
I see "In Progress" for 3 minutes (180 seconds), and then it shows as "Failed."
I would suggest you to move all you scripting task in a powershell file and copy it to a storage account linked with your custom activity. . Once done try to call it like below:
powershell .\script.ps1
You can also provide the path of the script in json like below:
{
"name": "MyCustomActivityPipeline",
"properties": {
"description": "Custom activity sample",
"activities": [{
"type": "Custom",
"name": "MyCustomActivity",
"linkedServiceName": {
"referenceName": "AzureBatchLinkedService",
"type": "LinkedServiceReference"
},
"typeProperties": {
"command": "helloworld.exe",
"folderPath": "customactv2/helloworld",
"resourceLinkedService": {
"referenceName": "StorageLinkedService",
"type": "LinkedServiceReference"
}
}
}]
}
}
Please try it and see if it helps. Also i would suggest you to troubleshoot the pipeline steps to look for detailed error.
Also to your second point "Some sites say about specifying a package (.zip file) that contains everything needed for the exe to execute." This is required when you are building a custom activity using dot net then it is must copy all the Dll's and Exe's for execution.
Hope it helps.

VSCode Custom Variables in Launch Settings?

Is there a way to add custom variables that I can use in my launch.json settings for debugging in VSCode? Currently, the only way I have found is to add them to my workspace settings and refer to the from the ${config} predefined variable.
I'd like to define variables/properties in the launch.json and use them. Here's an example of what that might look like if I wanted to add myCustomVar to all my URLs:
{
"version": "0.2.0",
"myCustomVar": "my_value",
"configurations": [
{
"name": "Page 1",
"type": "chrome",
"request": "launch",
"url": "http://localhost/page1.html?customVar=${myCustomVar}",
"sourceMaps": true,
"webRoot": "${workspaceFolder}/dev"
},
{
"name": "Page 2",
"type": "chrome",
"request": "launch",
"url": "http://localhost/page2.html?customVar=${myCustomVar}",
"sourceMaps": true,
"webRoot": "${workspaceFolder}/dev"
}
}
Input variables might work?
Command variables are already powerful but they lack a mechanism to configure the command being run for a specific use case. For example, it is not possible to pass a prompt message or a default value to a generic "user input prompt".
This limitation is solved with input variables which have the syntax: ${input:variableID}. The variableID refers to entries in the inputs section of launch.json and tasks.json, where additional configuration attributes are specified. Nesting of input variables is not supported.
The following example shows the overall structure of a tasks.json that makes use of input variables:
{
"version": "2.0.0",
"tasks": [
{
"label": "task name",
"command": "${input:variableID}"
// ...
}
],
"inputs": [
{
"id": "variableID",
"type": "type of input variable"
// type specific configuration attributes
}
]
}
Otherwise, you should be able to add custom settings to your VS Code settings.json file (it will warn you about "Unknown Configuration Setting") and insert them using ${config:myCustomVar}.

Task.Json triggers validation on invisible only fields

I am trying to create a Azure DevOps Pipelines Custom extension. I have a task.json where fields are visible on certain conditions.
For example:
{
"name": "actions",
"type": "picklist",
"label": "Actions",
"defaultValue": "Select",
"required": true,
"helpMarkDown": "Select an Action from the dropdown as per your requirement.",
"options": {
"New": "Add",
"Delete": "Delete"
}
},
{
"name": "backEndIPAddress",
"type": "string",
"label": "IP Address",
"required": true,
"defaultValue": "",
"helpMarkDown": "",
"visibleRule": "actions = New",
"validation": {
"expression": "isMatch(value,'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?){0,15}$','IgnoreCase')",
"message": "Invalid IP Address. Please try again!"
}
}
The issue when the IPAddress field is hidden, the validation is still tried and it fails. How to ensure that the fields are validated only if they are visible?
A few options:
Set a default value for the input
Update the regex to include ^$| at the start to allow empty values ('require':true will take care of the requiredness)
Remember that there should be a default isIpV4Address(value: string) function so you don't have to specify the regex.
From the docs it looks like there is an upcoming when clause which will dictate when the set of rules should trigger, I suppose this may be causing the currently unwanted behavior.
See also:
https://github.com/Microsoft/vsts-tasks/blob/1d75fa8f66aa1cf7a9cb62946939f30f087b2969/docs/taskinputvalidation.md

TFS 2018 - Custom Build Task with boolean parameters

I've created a custom build task and its extension for TFS 2018. Two of my parameter are boolean. On task.json I set the default value to false. When I execute a build definition with my task I get the following error:
System.Management.Automation.ParameterBindingArgumentTransformationException:
Cannot process argument transformation on parameter 'isToDeploy'.
Cannot convert value "System.String" to type "System.Boolean". Boolean
parameters accept only Boolean values and numbers, such as $True,
$False, 1 or 0. --->
System.Management.Automation.ArgumentTransformationMetadataException:
Cannot convert value "System.String" to type "System.Boolean". Boolean
parameters accept only Boolean values and numbers, such as $True,
$False, 1 or 0. --->
System.Management.Automation.PSInvalidCastException: Cannot convert
value "System.String" to type "System.Boolean". Boolean parameters
accept only Boolean values and numbers, such as $True, $False, 1 or 0.
Here is my powershell
[CmdletBinding()]
param(
[string][Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] $qaApiEndpoint,
[string][Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] $deployfxEndpoint,
[bool][Parameter(Mandatory=$true)] $isToDeploy,
[string][Parameter(Mandatory=$false)] $deploymentType,
[string][Parameter(Mandatory=$false)] $environment,
[bool][Parameter(Mandatory=$false)] $isToArchivePackage,
[string][Parameter(Mandatory=$false)] $archiveLocation
)
Here is my Task.json (input part) (ignore ??? as this task is still in development)
"inputs": [
{
"name": "qaApiEndpoint",
"type": "string",
"label": "QA Web API Endpoint",
"defaultValue": "",
"required": true,
"helpMarkDown": "Endpoint for the QA Web API.",
"groupName": "GeneralGroup"
},
{
"name": "deployfxEndpoint",
"type": "string",
"label": "Deploy Fx Endpoint???",
"defaultValue": "",
"required": true,
"helpMarkDown": "???",
"groupName": "GeneralGroup"
},
{
"name": "isToDeploy",
"type": "boolean",
"label": "Deploy?",
"defaultValue": false,
"required": false,
"helpMarkDown": "Should the task perform the application's deployment?",
"groupName": "DeploymentGroup"
},
{
"name": "deploymentType",
"type": "string",
"label": "Deployment Type",
"defaultValue": "",
"required": false,
"helpMarkDown": "Ex: Full, Update, Patch",
"groupName": "DeploymentGroup"
},
{
"name": "environment",
"type": "string",
"label": "Environment to deploy",
"defaultValue": "",
"required": false,
"helpMarkDown": "Ex: DEV, TST, QA, PRD",
"groupName": "DeploymentGroup"
},
{
"name": "isToArchivePackage",
"type": "boolean",
"label": "Archive Package?",
"defaultValue": false,
"required": false,
"helpMarkDown": "Should the package be archived?",
"groupName": "PackageGroup"
},
{
"name": "archiveLocation",
"type": "string",
"label": "Archive Location",
"defaultValue": "",
"required": false,
"helpMarkDown": "Path for the package archive",
"groupName": "PackageGroup"
}
]
Like the error message says, I've already tried to change the value, in Task.json, for the booleans to $False, 0 and even "false". I've also tried to change the type to bool instead and even change the parameters in json and powershell to string and then convert the values to boolean in powershell. All my tries ended up with the same error.
One thing even weirder is that I've deletied the booleans from powershell and json but I got the same error...which makes no sense at all and makes me question if i'm hitting some cache issue or something. (yes, I've restarted the machine in between some of the times).
==Edit==
The weird behavior above happens because I wasn't updating the task.json and vss-extension.json id. Need to do it between each try.
==End Edit==
The way I do to "update" my customs task is, I simply delete the task in the build definition, delete the extension from the collection and uninstall it from TFS, then I install everything again.
Combinations tested
boolean and false
boolean and 0
boolean and "false"
boolean and $False
boolean and "$False"
boolean and "$false"
boolean and $false
bool and 0
Not sure if this is still relevant or if you found a solution already.
Just providing an answer because I ran into the same issue a couple of days ago.
Was getting the same error and it appears that TFS stores its inputs as strings. For me the solution was to add -AsBool to the declaration of my variable / parameter in the executed PS1 script:
[CmdletBinding()]
[bool]$ExcludeGated = Get-VstsInput -Name ExcludeGated -AsBool
This however does require the use of function Get-VstsInput which comes with VstsTaskSdk
The JSON part for this particular Boolean looks like a standard entry:
{
"name": "ExcludeGated",
"type": "Boolean",
"label": "Gated Exclusion flag",
"defaultValue": "true",
"required": false,
"helpMarkDown": "your helpful markdown comment here"
}

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