## [debug]无法获取发布任务状态,VSTS发布管理,回滚步骤 [英] ##[debug]Could not obtain release tasks status, VSTS Release Management, Rollback step

查看:84
本文介绍了## [debug]无法获取发布任务状态,VSTS发布管理,回滚步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VSTS进行构建和发布管理,在发布​​定义中使用回滚步骤来回滚部署,如果任何步骤中断了发布定义。但是当我看到回滚步骤的调试日志时,它给出了错误"## [debug]可能
没有获得释放任务状态"并执行我的回滚Power Shell脚本,即使步骤成功或失败。

I am using VSTS for Build and Release management, in release definition using Rollback step to rollback the deployment if any of the step breaks from release definition. But when I see the debug logs for the Roll back step it is giving the error "##[debug]Could not obtain release tasks status" and executing my rollback Power Shell script even if the steps are successful or failed.

##[debug]Getting Personal Access Token for the Run

##[debug]Calling https://<myaccountname>.vsrm.visualstudio.com/<myteamprojectname>/_apis/release/releases/102/environments/167/tasks?api-version=2.1-preview.1 using obtained PAT token

##[debug]Could not obtain release tasks status

##[debug]The remote server returned an error: (500) Internal Server Error.

##[debug]Release Query unsuccessful.

##[debug]obtained task execution history as {}

以下是我的脚本快照。 

Below is my script snap. 

提前感谢您,我们非常感谢您解决此问题。

Thank you in advance, any help to resolve this is much appreciated.

try { #Obtain tasks JSON $jsonobject = ConvertFrom-Json $env:Release_Tasks } catch { Write-Host -Verbose "Error converting from json" Write-Host -Verbose $Error } [bool] $isRestoreRequired = $false #Check status of all tasks foreach ($task in $jsonobject | Get-Member -MemberType NoteProperty) { $taskproperty = $jsonobject.$($task.Name) | ConvertFrom-Json Write-Host -Verbose "Task $($taskproperty.Name) with rank $($task.Name) has status $($taskproperty.Status)" #Perform rollback action required in case $task.Name has status failed if($taskproperty.Status -eq "failure" -and $taskproperty.Name -ne "Backup") { $isRestoreRequired = $true } } # Action based on flag $isRestoreRequired

我在内部使用构建服务器,并在其上部署了构建代理。我在构建服务器上的agent \tasks \Rollback \1.1.2目录中获得了Rollback步骤的PowerShell脚本,Runpowershellwithtaskcontext.ps1

I am using build server on premise with build agent deployed on it. I got the PowerShell script of Rollback steps in agent\tasks\Rollback\1.1.2 directory on build server, Runpowershellwithtaskcontext.ps1

Param(
	[string] $type,
	[string] $rollbackpowershellfile,
	[string] $additionalarguments,
	[string] $workingFolder,
	[string] $script
)

Write-Verbose -Verbose "Type= $type" 
Write-Verbose -Verbose "ScriptPath= $rollbackpowershellfile" 
Write-Verbose -Verbose "ScriptArguments= $additionalarguments" 
Write-Verbose -Verbose "workingFolder = $workingFolder" 
Write-Verbose -Verbose "inlineScripe = $script" 
import-module "Microsoft.TeamFoundation.DistributedTask.Task.Common"

# Construct the REST URL to obtain Build ID
$releasequeryuri = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)$($env:SYSTEM_TEAMPROJECT)/_apis/release/releases/$($env:Release_ReleaseId)/environments/$($env:RELEASE_ENVIRONMENTURI.Split('/')[-1])/tasks?api-version=2.1-preview.1"
$taskexecutioninfo = @{}
$releasequeryresult = $null
$personalAccessToken = $null

# Wait for 60 seconds for the job context to persist with the server (for accuracy)
sleep -Seconds 60

try
{
    Write-Verbose -Verbose "Getting Personal Access Token for the Run" 
    $vssEndPoint = Get-ServiceEndPoint -Name "SystemVssConnection" -Context $distributedTaskContext
    $personalAccessToken = $vssEndpoint.Authorization.Parameters.AccessToken

    if (!$personalAccessToken) 
    { 
       throw "Could not extract personal access token. Exitting"     
    } 

    # Invoke the REST call and capture the results
    Write-Verbose -Verbose "Calling $releasequeryuri using obtained PAT token"
    if ($personalAccessToken)
    {
        $releasequeryresult = Invoke-RestMethod -Uri $releasequeryuri -Method Get -ContentType "application/json" -Headers @{Authorization= "Bearer " + $personalAccessToken}            
    }
    else
    {
        Write-Verbose -Verbose "auth info not recieved"
    }
}
catch
{
    Write-Verbose -Verbose "Could not obtain release tasks status"
    foreach($err in $Error)
    {
        Write-Verbose -Verbose $err
    }

    $releasequeryresult = $null
}


if (!$releasequeryresult -or $releasequeryresult.count -eq 0)
{
    Write-Verbose -Verbose  "Release Query unsuccessful."
}
else
{    
    $jobtasks = $releasequeryresult.value | Sort-Object dateStarted
    $ignoreResultentry = $true

    Write-Verbose -Verbose  "Obtained $($jobtasks.Count) tasks from task history"
    foreach ($task in $jobtasks)
    {
        Write-Verbose -Verbose "Task $($task.rank) $($task.name) $($task.status)"
        if ($ignoreResultentry -and $task.name -eq "Release")
         {
            Write-Verbose -Verbose "skipping the the release job result"
            $ignoreResultentry = $false
         }
         elseif (!$taskexecutioninfo.ContainsKey($task.rank.ToString()))
         {  
             $newentry = @{}
             $newentry.Add("Id", $($task.rank).ToString())
             $newentry.Add("Name", $($task.name).ToString())
             $newentry.Add("Status", $($task.status).ToString())
             $taskentrystr = ConvertTo-Json $newentry -Compress
             $taskexecutioninfo.Add($task.rank.ToString(), $taskentrystr)
         }
    }
}

$outputvariabletoSet = ConvertTo-Json $taskexecutioninfo -Compress
Write-Verbose -Verbose "obtained task execution history as $outputvariabletoSet"
$env:Release_Tasks = $outputvariabletoSet
Write-Verbose -Verbose "##vso[task.setvariable variable=Release_Tasks;]$outputvariabletoSet"

Write-Verbose -Verbose "Running $rollbackpowershellfile"
if($workingFolder)
{
    if(!(Test-Path $workingFolder -PathType Container))
    {
        throw ("$workingFolder does not exist");
    }
    Write-Verbose "Setting working directory to $workingFolder"
    Set-Location $workingFolder
}

if($type -eq "InlineScript")
{
	Write-Verbose -Verbose "Invoking $script"
    Invoke-Expression $script
}

if($type -eq "FilePath")
{
	if (Test-Path $rollbackpowershellfile)
	{
		$scriptCommand = "& `"$rollbackpowershellfile`" $additionalarguments" 
		Write-Verbose -Verbose "Rollback script execution command = $scriptCommand" 
		Invoke-Expression -Command $scriptCommand
	} 
	else
	{
		Write-Error -Verbose "$rollbackpowershellfile not found"
	}
}

Write-Verbose -Verbose "Exitting script runpowershellwithtaskcontext"

我得到的错误来自第41行,当它调用API时

The error I am getting is from the line number 41 when it calls API

        $releasequeryresult = Invoke-RestMethod -Uri $releasequeryuri -Method Get -ContentType "application/json" -Headers @{Authorization= "Bearer " + $personalAccessToken}            

推荐答案

Hello Milind T. Patil,

感谢您在此处发帖。

你的脚本看起来不错,500内部服务器错误是一般网络错误,请交叉检查所有网络连接并尝试再次。  
我们也很乐意为您提供反馈,我们很乐意为您提供更多信息。

参考: https:// blogs。 msdn.microsoft.com/visualstudioalm/2016/03/28/implement-rollback-with-release-management-for-tfs-2015 /

问候,


这篇关于## [debug]无法获取发布任务状态,VSTS发布管理,回滚步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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