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+
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.