Environment status check before deployment

Hi,

Is it possible to check whether the servers using in an environment for a particular project (something like Website project pre-production) are online before attempting a deployment? We are having problems with servers dropping from DNS which causes them to disconnect from Octopus Deploy.

I was hoping there would be a switch in octo.exe but I didn’t find anything.

Thanks
Andy

Hi Andy,

Thanks for getting in touch! There’s not a straight way to do so from Octo.exe, but you could add a step at the beggining of your deployment process to force a health check on all the machines on that environment using the REST API. When you start the health check you’ll get a response with a task link where you can check the status of the health check task.

I’d recommend you to run this step from the Octopus Server to make sure it runs only once (and not one time per machine on an env).

If you need help writing the script to do the API Calls, let me know and i’ll sketch something for you.

Thanks!

Dalmiro

What is the actual API that forces the health check, though?
Thanks!
-Jonathan

Hi Jonathan,

Thanks for reaching out. You can use the cmdlet Start-OctopusHealthCheck from the Octoposh module to trigger a HealthCheck https://github.com/Dalmirog/OctoPosh/wiki/Start-OctopusHealthCheck

If you still need an actual API example for this, let me know and i’ll send you one.

Thanks!

Dalmiro

Thanks for your quick response Dalmiro. Yes, I’d still like to know how to do this from the API. I need to verify the health of our tentacles from a Process Step. If a tentacle is gone (in a cloud deployment), I’ve found that a tentacle can be gone for 1 hr before it appears as disconnected.

Hi Jonathan,

Here’s an example for the REST API call using Powershell

$OctopusURL = "http://YourURL"
$OctopusAPIKey = "YourOctopusAPIKey"
$environmentID = "YourEnvironmentID" #Id of the environment where you want to run the health check. During a deployment you can use the variable $OctopusParameters['Octopus.Environment.Id'] to get this value.

$header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey }

$body = @"
{
    "Name":"Health",
    "Description":"Check Deployment Target health in Development",
    "Arguments":{
        "Timeout":"00:05:00",
        "EnvironmentId":"$environmentID"
        }
 }
"@

Invoke-WebRequest -Uri $OctopusURL/api/tasks -Body $body -Headers $header -Method Post

Hope that helps

Dalmiro

Thanks for your help Dalmiro. I’m proceeding down this path, but haven’t been able to test it yet.

{
    ErrorMessage: "You do not have permission to perform this action. Please contact your Octopus administrator. Missing permission: TaskCreate"
 
    HelpText: "This action requires permission to explicitly create (run) server tasks. At least one of your teams has this permission in a limited scope, but this doesn't cover the project or environment in question. Teams that have enough permission include: Octopus Administrators."
}

Our Octopus admin says I have TaskCreate access (via my team’s access to a role he created with “TaskCreate” enabled), though. I’ll let you know how it goes once I can gain access to the API. I’ll probably look for another topic related to this specific permissions problem.

Thanks!

-Jonathan

Hi Jonathan,

The team that grants you the “TaskCreate” role should be scoped to “All projects”, and not just the ones that are currently using that Environment. That’s most likely why you are getting that error.

Thanks,

Dalmiro

hi, when i execute the following script below get a "remote server returned a 500 error"
Just wondering if this invoke-webrequest still works,

Thank you,
-Greg

$OctopusURL = “http://YourURL
$OctopusAPIKey = “YourOctopusAPIKey”
$environmentID = “YourEnvironmentID” #Id of the environment where you want to run the health check. During a deployment you can use the variable $OctopusParameters[‘Octopus.Environment.Id’] to get this value.

$header = @{ “X-Octopus-ApiKey” = $OctopusAPIKey }

$body = @"
{
“Name”:“Health”,
“Description”:“Check Deployment Target health in Development”,
“Arguments”:{
“Timeout”:“00:05:00”,
“EnvironmentId”:"$environmentID"
}
}
"@

Invoke-WebRequest -Uri $OctopusURL/api/tasks -Body $body -Headers $header -Method Post

Hi,

Thanks for reaching out. It should still be working. Are you sure you are using the right URL?

There’s an OSS project Called Octoposh which has a cmdlet for this as well. Maybe you can give that a try too: https://github.com/Dalmirog/OctoPosh/wiki/Start-OctopusHealthCheck

*Be aware of this issue when using that cmdlet: https://github.com/Dalmirog/OctoPosh/issues/194 *

Project site: http://octoposh.net/

Regards,
Dalmiro

Hi Dalmiro,

I worked out that I was using environment name instead of ID…can use the
environment name instead ? for example: Development instead of
environmentID-80

I’m not really liking octoposh I rather use invoke-webrequest

Thank you,

Regards,
Greg

Hi Greg,

Not possible using the Name, you’ll need the ID.

You can get it using Octoposh like this:

$environment = Get-OctopusEnvironment -EnvironmentName "Development"

$environment.id

Or using the API to GET /api/environments/all, then filter the environment you want and get its ID.

Thanks!
Dalmiro