1
votes

We are using Octopus Deploy to deploy our application. After a successful deployment, we have an additional step of sending a notification to Slack with the deployment status.

However, this previously-working step is started failing a few days ago. I have been so far unable to find the root cause of the failure.

We are getting this error in the Slack log:

Invoke-RestMethod : The request was aborted: Could not create SSL/TLS secure channel.
+     Invoke-RestMethod -Method POST -Body ($payload | ConvertTo-Json - ...
Error
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException+ FullyQualifiedError IdWebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
The remote script failed with exit code 1

Things we've tried so far:

  • Verified the TLS version on the server.
  • Reviewed a few articles from the Internet to bypass SSL/TLS

Here's the PowerShell script that we are using:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Invoke-RestMethod -Method POST -Body ($payload | ConvertTo-Json -Depth 4) -Uri $OctopusParameters['HookUrl']  -ContentType 'application/json'
2

2 Answers

1
votes

I just needed to insert the following line immediately before the existing Invoke-RestMethod line in my PowerShell Slack notification script to get things working again:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

See this related answer for more details about what's going on here: https://stackoverflow.com/a/45692875/12484

0
votes

I update the template with below code , update project step and it worked .

 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

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3, [Net.SecurityProtocolType]::Tls, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Tls12

Invoke-RestMethod -Method POST -Body ($payload | ConvertTo-Json -Depth 4) -Uri $OctopusParameters['HookUrl']  -ContentType 'application/json'