为什么我的VSTS自定义任务通过退出代码1?

问题描述 投票:3回答:1

我有以下恼人的问题。我的自定义VSTS构建任务不会失败。它总是通过,而$ LASTEXITCODE则为零。

代码按预期执行。它会在日志中生成错误。尽管如此,该步骤仍然成功,并且构建/发布仍在继续。

屏幕截图:screenshot我已经包含了一个带有退出代码的写主机,它也显示了exitcode 1。

码:

Try {
    ....
    #Loop through the server list
    Foreach ($Server in $machines) 
    {
        # Use SSL or not    
        If($UseSSL -eq $true) 
        {
            Write-Host "Connecting to $Server using a SSL connection (TCP/5986), Skip CA Check: $CheckCA ..."
            $s = New-PSSession -ComputerName $Server -Credential $Cred -UseSSL -SessionOption $SessionOptions
        }
        Else
        {
            Write-Host "Connecting to $Server with an unsecure connection (TCP/5985) ..."
            $s = New-PSSession -ComputerName $Server -Credential $Cred
        }

        # Run
        $ExitCode = Invoke-Command -Session $s -ScriptBlock $script -ArgumentList $ApplicationPoolName,$Action,$Killswitch

        # Cleanup the session
        Write-Host "Closing connection to $Server."
        Remove-PSSession -Session $s
    }
} Catch {
    Write-Host "##vso[task.logissue type=Error;]$Error"
    $ExitCode = 1
} Finally {
    #Leave TFS/VSTS trace
    if (Get-Command -Name Trace-VstsEnteringInvocation -ErrorAction SilentlyContinue) {
        Trace-VstsLeavingInvocation $MyInvocation
    }
    write-host "ExitCode: $ExitCode"
    Exit $ExitCode
}

我在这里失踪了什么?

tfs azure-devops azure-pipelines-build-task azure-pipelines-release-task
1个回答
2
投票

我通过删除finally部分来解决它。

不工作:

try {
    .... do stuff ....
} catch {
   write-error "some error"
   exit 1
} Finally {
  .. some final steps ...
}

工作:

try {
    .... do stuff ....
} catch {
   write-error "some error"
   exit 1
} 
© www.soinside.com 2019 - 2024. All rights reserved.