Hi,
I’m running a powershell script to send notifications to slack from octopus. If I run the script manually (from octopus server) it works just fine but when it’s a process step is throwing an error.
This is the script:
$hook = “https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
$hook_config = @{
channel = “#octopus-deploy”;
username = “OctopusDeploy”;
icon_url = “http://octopusdeploy.com/content/resources/favicon.png”;
};
function Slack-Rich-Notification ($hook_config, $notification)
{
$payload = @{
channel = $hook_config[“channel”];
username = $hook_config[“username”];
icon_url = $hook_config[“icon_url”];
attachments = @(
@{
fallback = $notification[“fallback”];
color = $notification[“color”];
fields = @(
@{
title = $notification[“title”];
value = $notification[“value”];
});
};
);
}
Invoke-Restmethod -Method POST -ContentType application/json -Body ($payload | ConvertTo-Json -Depth 4) -Uri $hook
}
$success_notification = @{
title = “Success”;
value = “Deploy $OctopusProjectName release $OctopusReleaseNumber to $OctopusEnvironmentName”;
fallback = “Deployed $OctopusProjectName release $OctopusReleaseNumber to $OctopusEnvironmentName successfully”;
color = “good”;
};
$hook;
$success_notification;
$PSVersionTable.PSVersion;
Slack-Rich-Notification $hook_config $success_notification
And the error:
Invoke-Restmethod : The remote name could not be resolved: 'hooks.slack.com’
At C:\Octopus\Work\20160627103714-70\Script.ps1:28 char:5
-
Invoke-Restmethod -Method POST -ContentType application/json -Body
($payload …
-
+ CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : System.Net.WebException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Fatal
The remote script failed with exit code 1