KBEC-00347 - Using PowerShell to call REST API of CloudBees CD (CloudBees Flow)

Article ID:360032826832
1 minute readKnowledge base

Summary:

This article discusses how to use PowerShell to call the REST API of CloudBees CD (CloudBees Flow).

Solution:

Either Invoke-WebRequest or Invoke-RestMethodcan be used to interact with the RESTful API of CloudBees CD (CloudBees Flow). When a trusted certificate is not available using https, the following error may occur.

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

In this case, below lines need to be added into the code before calling Invoke-WebRequest or Invoke-RestMethod.

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@

[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

An example PowerShell script is attached to this article for reference.

See also:

Applies to:

  • Production version: 5.2+

  • OS: Windows

  • PowerShell version: 3.0+