Reputation: 347
I am working on creating a VSTS task for a release and am getting the above error. I know what the error means, but I am not sure how to resolve as this is the first time I am creating a custom task.
Essentially the task takes a source file and FTP's it up to Azure, based on published profile settings it attains within the script.
Here is the PowerShell code:
[CmdletBinding()]
param()
Trace-VstsEnteringInvocation $MyInvocation
$appdirectory = get-vstsinput -Name appdirectory
$webappname = get-vstsinput -Name webappname
$ResourceGroupName = get-vstsinput -Name ResourceGroupName
#write-host $appdirectory
$location="East US"
try {
# Get inputs.
# Get publishing profile for the web app
$xml = [xml](Get-AzureRmWebAppPublishingProfile -Name $webappname `
-ResourceGroupName $ResourceGroupName `
-OutputFile null)
# Extracts connection information from publishing profile
$username = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@userName").value
$password = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@userPWD").value
$url = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@publishUrl").value
Write-Output "$username"
Write-Output "$password"
Write-Output "$url"
#Write-Output "$localpath"
# Upload files recursively
Set-Location $appdirectory
$webclient = New-Object -TypeName System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($username,$password)
$files = Get-ChildItem -Path $appdirectory -Recurse | Where-Object{!($_.PSIsContainer)}
foreach ($file in $files)
{
$relativepath = (Resolve-Path -Path $file.FullName -Relative).Replace(".\", "").Replace('\', '/')
$uri = New-Object System.Uri("$url/$relativepath")
"Uploading to " + $uri.AbsoluteUri
$webclient.UploadFile($uri, $file.FullName)
}
$webclient.Dispose()
} finally {
Trace-VstsLeavingInvocation $MyInvocation
}
Associated with this is a JSON file that is used for the build and the release manager within TFS. Here is the code for that:
{
"id": "LongStringofNumbers",
"name": "NameOfTask",
"friendlyName": "FriendlyNameOfTask",
"description": "Build Task that will upload a file or folder to a destination in Azure using Published Profile Credentials.",
"helpMarkDown": "",
"category": "Build",
"visibility": [
"Build"
],
"runsOn": [
"Agent",
"DeploymentGroup"
],
"author": "ME",
"version": {
"Major": 0,
"Minor": 0,
"Patch": 16
},
"instanceNameFormat": "Uploads File Using Published Profile Credentials",
"groups": [
{
"name": "advanced",
"displayName": "Advanced",
"isExpanded": true
}
],
"inputs": [
{
"name": "appdirectory",
"type": "filePath",
"label": "Source Path",
"defaultValue": "",
"required": true,
"helpMarkDown": "Location of file(s) for uploading to Azure."
},
{
"name": "webappname",
"type": "string",
"label": "Azure Webapp name",
"defaultValue": "",
"required": true,
"helpMarkDown": "Azure App name; I.E. - 900014campuslinkapi."
},
{
"name": "ResourceGroupName",
"type": "string",
"label": "Azure Resource Group name",
"defaultValue": "",
"required": true,
"helpMarkDown": "Azure Resource Group Name I.E. - 900014-prod."
}
],
"execution": {
"PowerShell3": {
"target": "powershell.ps1",
"platforms": [
"windows"
],
"argumentFormat": "",
"workingDirectory": "$(currentDirectory)"
}
}
}
So the error is stating I need the three mandatory parameters which from the JSON file is added as a field in the release manager. But I don't think the script and the JSON file are connecting for some reason so even when I place in items in the release manager fields, it still fails with the error. Here is the image:
Upvotes: 2
Views: 10021
Reputation: 59045
You still have to pull the values into your script. Look at how the reference tasks function, or look at the documentation.
Your script needs to import and use the task SDK and call Get-VstsInput
to retrieve the values.
For what it's worth, you should use the PowerShell3
handler, as PowerShell
is legacy.
Another option is to not create a custom task if this is intended only for internal use, although 100% bias on my part. I dislike turning simple PowerShell scripts into opaque black boxes and prefer to drive everything from source control.
Upvotes: 0