Deploying Release via the Rest API

In our current deployment octopus processes, we are deploying code via Octo.exe using the octo commands that look like this

Octo.exe deploy-release --project %octo_projectName% --releaseNumber 1.0.%BUILD_NUMBER% --server %OctoServerName% --apiKey %octo_deploymentManagerApiKey% --deployto “DeployServer”

I am currently trying to move this command inside of Octopus in order to create an automatic rollback process where I can redeploy a release if my current deployment fails. I would rather not use Octo.exe and would rather use a powershell script in some way that doesn’t have a dependency on some package being imported in. From looking at the documentation for the REST API I don’t see a deployment method, does one exist? If there is, where is the document that explains the set of commands?

Hi,

Thanks for reaching out. We are a bit behind on that part of the documentation; sorry for that.

This script should give you a good starting point: https://github.com/Dalmirog/Octopus_Snippets/blob/master/REST/CreateReleaseAndDeploy.ps1

Hope that helps!

Dalmiro

Dalmiro,

I just tried accessing your code again and get a 404 error. Is that file still available?

Hey,

I re-organized the folder structure of that project. Here’s the file: https://github.com/Dalmirog/Octopus_Snippets/blob/master/REST%20API/Release_CreateAndDeploy.ps1

Thanks,

Dalmiro

Thanks Dalmiro. That’s exactly what I needed.

What if I want to re-deploy the current version? I built the request according to your snippet (using the current version #), but then I get an HTTP 400 error back.

Hi Timothy,

I wrote a script that will take the latest version deployed to the environment of your choice, and it will re-deploy it to the same environment

https://github.com/Dalmirog/Octopus_Snippets/blob/master/REST%20API/Release_ReDeployLatestRelease.ps1

Hope that helps!

Dalmiro

It does help! Thank you for sharing!

Timothy