How to execute operations runbook from deployment

We would like to use Operations runbook to set our Azure web app hosted application to offline state. Runbook would drop with Kudu Rest Api “appoffline.html” file to the web app root.

We would like to execute this as part of the deployment in scenarios such as database changes requiring downtime with some deployment flag. I didn’t find ready deployment step that could be used to run a Runbook this ways, is it possible to use Octopus Api for this or any easier way?

Hi @joona_hook,

Thanks for getting in touch! Unfortunately at the moment there’s no built-in deployment step to run a runbook, though this is certainly something we’d like to add in at some stage in the future. For now there are a couple of options to get around this, however.

The easiest would probably be to reverse this, where you execute the deployment from the runbook. This is done by configuring a Deploy a Release step in your runbook process, though this hits on a limitation where you can’t select the same project in this step. You can get around this by binding the project field to a variable that evaluates to the same project name that the runbook is running in.

The second option would be to make an API call in a deployment step to execute the runbook. I’ve found a sample script using the Octopus.client (an open source .NET library) that looks like this:

var endpoint = new OctopusServerEndpoint("http://localhost:8065");
var repository = new OctopusRepository(endpoint);
repository.Users.SignIn("Admin", "password");

var runbookRun = new RunbookRunResource();
runbookRun.RunbookId = "Runbooks-1";
runbookRun.RunbookSnapshotId = "RunbookSnapshots-41";
runbookRun.EnvironmentId = "Environments-1";

You can get the runbook and runbook snapshot IDs by visiting /api/runbooksnapshots and the environment ID by visiting /api/environments.

You can reference more details on the API in the following wiki.

I hope that helps! Let me know how you go or if you have any further questions going forward. :slight_smile:

Best regards,