Try to search your question here, if you can't find : Ask Any Question Now ?

Rest call from Powershell on Azure DevOps issue

HomeCategory: stackoverflowRest call from Powershell on Azure DevOps issue
Avatarsourav asked 1 week ago

I’m trying to call rest service on K8S from powershell Agent Job task on Azure DevOps.

$TOKEN=""
$APISERVER="https://xyz.sk1.us-east-2.eks.amazonaws.com"

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $True }
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$headers = @{
    'Authorization' = 'Bearer ' + $TOKEN
}

#Invoke-RestMethod -Method Get -Uri $APISERVER/api/v1/namespaces/default/pods/ -Headers $headers

try {
    Invoke-RestMethod -Method Get -Uri APISERVER/api/v1/namespaces/default/pods/ -Headers $headers
}
catch {
    $_.Exception | Format-List -Force
}

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null

Exception:

Status         : SendFailure
Response       :
Message        : The underlying connection was closed: An unexpected error occurred on a send.
Data           : {}
InnerException : System.Management.Automation.PSInvalidOperationException: There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the
                 System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was:  $True
                    at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
                    at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
TargetSite     : System.Net.WebResponse GetResponse(System.Net.WebRequest)
StackTrace     :    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
                    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
HelpLink       :
Source         : Microsoft.PowerShell.Commands.Utility
HResult        : -2146233079

As you can see in script, I already changed security protocol and added ServerCertificateValidationCallback delegate.

Any help would be appreciated, thanks.

EDIT1: similar approach using curl works. Same token, same address, also insecure.

1 Answers
Best Answer
AvatarMikhail answered 1 week ago
Your Answer

2 + 15 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com