powershell - 使用 TFS vNext 任务 : A parameter cannot be found that matches parameter name 的问题

标签 powershell tfs tfsbuild azure-pipelines azure-pipelines-build-task

我正在尝试创建一个简单的 TFS vNext 任务,使用 Powershell 执行 Powershell 脚本。

我可以加载任务,但在使用任务触发发布后,我得到了

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

我的 task.json 如下。

{
    "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)"
        }
    }
}

我的 Powershell 脚本在这里。

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

# 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
}

我有另一个简单的任务,它不带任何参数并且工作得很好。

有什么建议吗?

我错过了什么?

最佳答案

如果您使用的是 VSTS 构建任务 SDK,则需要使用 Powershell 3..

“执行”:{“PowerShell3”:{“目标”:“ManageIIS.ps1”,}}

关于powershell - 使用 TFS vNext 任务 : A parameter cannot be found that matches parameter name 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40899416/

相关文章:

powershell - PowerTools 更新-TfsWorkspace 未获取最新版本

msbuild - 使用 $(BuildAgentId) 时出现 Team Build TF10122 错误

powershell - $PSScriptRoot 和 $MyInvocation 之间的功能差异

function - 具有管道或直接输入的多个参数

linux - Powershell查询WINDOWS->LINUX

azure - 配置 TFS-Azure 部署以使用 "Release"进行构建

Nuget 错误 : Please provide credentials for: https://www. myget.org/F

PowerShell 脚本将 SQL 导出为 CSV 添加分隔符

tfs - 在 TFS 中,是否可以进行查询以返回所有前置任务处于关闭或已解决状态的所有工作项?

c# - 如何在不重新部署 webApp 的情况下通过 TFS 删除 WebServer 中的特定文件(未使用的文件)。 C#、.Net