Search code examples
powershelltfstfsbuildazure-pipelinesazure-pipelines-build-task

Issue with using a TFS vNext task: A parameter cannot be found that matches parameter name


I am trying to create a simple TFS vNext task, using Powershell to execute a Powershell script.

I could load the task, but after I trigger a release using the task, I get

##[error]System.Management.Automation.ParameterBindingException: A parameter cannot be found that matches parameter name 'PoolName'.

My task.json is as below.

{
    "id": "7fe28fb2-c323-4494-beb6-b5c5939b09e7",
    "name": "ManageIIS",
    "friendlyName": "ManageIIS",
    "description": "ManageIIS",
    "helpMarkDown": "ManageIIS",
    "category": "Utility",
    "visibility": [
        "Build"
    ],
    "author": "Baskar Lingam",
    "version": {
        "Major": 1,
        "Minor": 0,
        "Patch": 3
    },
    "demands": [],
    "minimumAgentVersion": "1.83.0",
    "groups": [
        {
            "name": "advanced",
            "displayName": "Advanced",
            "isExpanded": false
        }
    ],
    "instanceNameFormat": "ManageIIS",
    "inputs": [
    {
      "name": "PoolName",
      "type": "string",
      "label": "Application Pool Name",
      "required": true,
      "defaultValue": "AppPoolName"
    },
    {
      "name": "AppPoolAction",
      "type": "pickList",
      "label": "App Pool Action (Stop or Start)",
      "required": true,
      "defaultValue": "",
      "helpMarkDown": "Name of the Database",
      "options": {
        "Stop": "Stop App Pool",
        "Start": "Start App Pool"
      }
    },
    {
      "name": "ResetIIS",
      "type": "boolean",
      "label": "Reset IIS",
      "defaultValue": "false",
      "required": true,
      "helpMarkDown": "To reset IIS on a web server"
    }
  ],
    "execution": {
        "PowerShell": {
            "target": "ManageIIS.ps1",
            "argumentFormat": "",
            "workingDirectory": "$(currentDirectory)"
        }
    }
}

And my Powershell script is here.

#####################################################################

# Author        : Baskar Lingam Ramachandran
# Created Date  : 25th Nov 2016
# Updated Date  : 30th Nov 2016

######################################################################

[CmdletBinding()]
Param()

Trace-VstsEnteringInvocation $MyInvocation

try
{
    # Get the inputs.
    [string]$PoolName = Get-VstsInput -Name PoolName
    [string]$AppPoolAction = Get-VstsInput -Name AppPoolAction
    [bool]$ResetIIS = Get-VstsInput -Name ResetIIS -AsBool

    # Load the require module to manage IIS
    <#if(-not(Get-Module WebAdministration))
    {
        Import-Module WebAdministration
    }
    #>

    # Code for App pool stop or start
    if (($AppPoolAction -eq "Stop") -or ($AppPoolAction -eq "Start"))
    {
        if(-not($PoolName))
            {
                Write-Host "`t`tApp pool name is not provided. Please provide the same.`r`n" -ForegroundColor Green
            }
        else
            {
                if($AppPoolAction -eq "Stop")
                {
                    if(Test-Path IIS:\AppPools\$PoolName)
                    {
                        Write-Host "`t`tApp Pool $PoolName exists`r`n"
                        if(-not((Get-WebAppPoolState $PoolName).Value -eq "stopped"))
                        {

                            Write-Host "`t`t-------------------------------------------------`r`n"
                            Write-Host "`t`tStopping application pool $PoolName`r`n"
                            Write-Host "`t`t-------------------------------------------------`r`n"

                            Write-Host "`t`tApp Pool $PoolName is not stopped. Stopping it now.`r`n" -ForegroundColor DarkYellow
                            Stop-WebAppPool $PoolName
                            Write-Host "`t`tThe command execution is complete.`r`n" -ForegroundColor Cyan
                            $appPoolState = Get-WebAppPoolState $PoolName
                            Write-Host "`t`tThe current state of the app pool $PoolName is $($appPoolState.Value).`r`n" -ForegroundColor DarkMagenta
                        }
                        else
                        {
                            Write-Host "`t`tApp Pool $PoolName is already stopped.`r`n" -ForegroundColor DarkGreen
                        }
                    }
                    else
                    {
                        Write-Host "`t`tApp Pool $PoolName does not exist`r`n" -ForegroundColor DarkRed
                    }            
                }
                if($AppPoolAction -eq "Start")
                {
                    if(Test-Path IIS:\AppPools\$PoolName)
                    {
                        Write-Host "`t`tApp Pool $PoolName exists`r`n"
                        if(-not((Get-WebAppPoolState $PoolName).Value -eq "Started"))
                        {

                            Write-Host "`t`t-------------------------------------------------`r`n"
                            Write-Host "`t`tStarting application pool $PoolName`r`n"
                            Write-Host "`t`t-------------------------------------------------`r`n"

                            Write-Host "`t`tApp Pool $PoolName is not started. Starting it now.`r`n" -ForegroundColor DarkYellow
                            Start-WebAppPool $PoolName
                            Write-Host "`t`tThe command execution is complete.`r`n" -ForegroundColor Cyan
                            $appPoolState = Get-WebAppPoolState $PoolName
                            Write-Host "`t`tThe current state of the app pool $PoolName is $($appPoolState.Value).`r`n" -ForegroundColor DarkMagenta
                        }
                        else
                        {
                            Write-Host "`t`tApp Pool $PoolName is already started.`r`n" -ForegroundColor DarkGreen
                        }
                    }
                    else
                    {
                        Write-Host "`t`tApp Pool $PoolName does not exist`r`n" -ForegroundColor DarkRed
                    }            
                }
            }
        }

    if ($ResetIIS -eq "true")
    {
        iisreset -stop -noforce
        if ($LASTEXITCODE -eq 0)
        {
            Write-Host "`t`tInternet services successfully stopped`r`n" -ForegroundColor DarkGreen
        }
        iisreset -start -noforce
        if ($LASTEXITCODE -eq 0)
        {
            Write-Host "`t`tInternet services successfully started`r`n" -ForegroundColor DarkRed
        }
    }

} finally {
    Trace-VstsLeavingInvocation $MyInvocation
}

I have another simple task which does not take any parameter and it works perfectly fine.

Any pointers?

What am I missing?


Solution

  • If you are using the VSTS Build Task SDK you need to be using Powershell 3..

    "execution": { "PowerShell3": { "target": "ManageIIS.ps1", } }