注册环境失败 [英] Register-Environment Failing

查看:56
本文介绍了注册环境失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Azure DevOps上创建发布定义.我认为PowerShellOnTargetMachines.ps1中的Register-Environment函数失败:

  try{$连接= Get-VssConnection -TaskContext $ distributedTaskContext写详细信息启动环境的Register-Environment cmdlet调用:带有过滤器$ machineFilter的$ environmentName"$ environment =注册环境-EnvironmentName $ environmentName -EnvironmentSpecification $ environmentName -UserName $ adminUserName -Password $ adminPassword -WinRmProtocol $ protocol -TestCertificate($ testCertificate -eq"true")-Connection $ connection -TaskContext $ distributedTaskContext -ReFilter详细写入对环境的完成的注册环境cmdlet调用:$ environmentName"写详细信息在环境名称:$ environmentName上启动Get-EnvironmentResources cmdlet调用"$ resources =获取环境资源-Environment $ environment如果($ resources.Count -eq 0){写遥测"Input_Validation"给定环境不存在任何机器"抛出(Get-LocalizedString -Key环境中不存在任何计算机:'{0}'进行部署" -ArgumentList $ environmentName)}$ resourcesPropertyBag = Get-ResourcesProperties -resources $ resources} 

出现以下错误(我已经省略了一些组织的信息,但是它在那里并且看起来很正确):

  2019-09-04T12:34:55.6886629Z ## [debug] VssConnection已创建2019-09-04T12:34:55.7518340Z ## [debug]启动环境的Register-Environment cmdlet调用:[machine] with filter [machine]2019-09-04T12:34:55.7843531Z ## [debug]开始创建环境cmdlet2019-09-04T12:34:55.7872731Z ## [debug] UserName = [username]2019-09-04T12:34:55.7878292Z ## [debug] WinRmProtocol = HTTP2019-09-04T12:34:55.7878658Z ## [debug] TestCertificate = False2019-09-04T12:34:55.7878965Z ## [debug]无法为给定的json创建环境对象-解析值时遇到意外字符:A.路径'',行0,位置0.2019-09-04T12:34:55.7879241Z ## [debug] projectName = [projectName]2019-09-04T12:34:55.7879517Z ## [debug]从DTL服务获取环境[计算机]2019-09-04T12:34:55.8485808Z ## [debug]已处理:## vso [task.logissue type = error; code = {"Task_Internal_Error":找不到页面.};] 

我不知道该怎么办.任何想法表示赞赏.感谢您抽出宝贵的时间来阅读我的问题.

解决方案

基于Mike留下的评论的详细信息,该问题应由您正在使用的任务版本及其定义的功能脚本引起.

根据您在

您可以看到"PowerShellOnTargetMachines V2"中此cmdlet支持的参数.*不包括 TaskContext Connection .这就是为什么您收到错误消息无法为给定的json创建环境对象-解析值时遇到意外字符" 的原因.因为您在任务中输入的参数与 Register-Environment cmdlet的配置不匹配.


您可以尝试使用 PowerShellOnTargetMachines V1.* .在 1.* 中,我们支持参数 TaskContext Connection .

I am having trouble creating a release definition on Azure DevOps. I believe the Register-Environment function in PowerShellOnTargetMachines.ps1 is failing:

try
{
    $connection = Get-VssConnection -TaskContext $distributedTaskContext

    Write-Verbose "Starting Register-Environment cmdlet call for environment : $environmentName with filter $machineFilter"
    $environment = Register-Environment -EnvironmentName $environmentName -EnvironmentSpecification $environmentName -UserName $adminUserName -Password $adminPassword -WinRmProtocol $protocol -TestCertificate ($testCertificate -eq "true") -Connection $connection -TaskContext $distributedTaskContext -ResourceFilter $machineFilter
    Write-Verbose "Completed Register-Environment cmdlet call for environment : $environmentName"

    Write-Verbose "Starting Get-EnvironmentResources cmdlet call on environment name: $environmentName"
    $resources = Get-EnvironmentResources -Environment $environment

    if ($resources.Count -eq 0)
    {
        Write-Telemetry "Input_Validation" "No machine exists for given environment"
        throw (Get-LocalizedString -Key "No machine exists under environment: '{0}' for deployment" -ArgumentList $environmentName)
    }

    $resourcesPropertyBag = Get-ResourcesProperties -resources $resources
}

With the following error (I have omitted some of my organization's information, but it is there and looks right):

2019-09-04T12:34:55.6886629Z ##[debug]VssConnection created
2019-09-04T12:34:55.7518340Z ##[debug]Starting Register-Environment cmdlet call for environment : [machine] with filter [machine]
2019-09-04T12:34:55.7843531Z ##[debug]Begin Create-Environment cmdlet
2019-09-04T12:34:55.7872731Z ##[debug]UserName=[username]
2019-09-04T12:34:55.7878292Z ##[debug]WinRmProtocol=HTTP
2019-09-04T12:34:55.7878658Z ##[debug]TestCertificate=False
2019-09-04T12:34:55.7878965Z ##[debug]Unable to create a environment object for given json - Unexpected character encountered while parsing value: A. Path '', line 0, position 0.
2019-09-04T12:34:55.7879241Z ##[debug]projectName=[projectName]
2019-09-04T12:34:55.7879517Z ##[debug]Getting environment [machine] from DTL Service
2019-09-04T12:34:55.8485808Z ##[debug]Processed: ##vso[task.logissue type=error;code={"Task_Internal_Error":Page not found.};]

And I do not know what to do. Any ideas are appreciated. Thanks for taking the time to read my question.

解决方案

Based on the details which from comment that Mike left, the issue should caused by the the task version you are using and its feature script we defined.

According to the ticket description you raised in DC ticket:

I am trying to use V2 of the following 'PowerShellOnTargetMachines' PowerShell script for a release on azure devops, from azure-pipeline-tasks.

the version of PowerShellOnTargetMachines you are using is 2.*.

We can get the Register-Environment cmdlet script with decompile tool follow the method I showed in this case.

You can see the parameters this cmdlet supported in 'PowerShellOnTargetMachines V2.*' does not include TaskContext and Connection. That's why you receive the error message "Unable to create a environment object for given json - Unexpected character encountered while parsing value". Because the parameter you input in the task does not match the configuration of Register-Environment cmdlet.


You can try with PowerShellOnTargetMachines V1.*. In 1.* we support the parameters TaskContext and Connection.

这篇关于注册环境失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆