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:
- https://technet.microsoft.com/en-us/library/hh849901.aspx
- https://technet.microsoft.com/en-us/library/hh849971.aspx
Applies to:
- Production version: 5.2+
- OS: Windows
- PowerShell version: 3.0+
Comments
0 comments
Please sign in to leave a comment.