5

Please can anybody explain me how to create release using Octopus REST API.
I can create a release using octo.exe but have no idea how to do that using REST API.
I went through the http://localhost:8080/api, but cant figure it out how to create a release.

Is this REST api providing that feature??

New Developer
  • 3,245
  • 10
  • 41
  • 78
  • Yes, this is a RESTful API and they do provide an endpoint to create releases. Actually, they provide quite a lot of endpoints. However, most their documentation is not complete and nor do they provide an easy way to get started. If you have the option to use their tools I would recommend doing so. The tools can be found at https://octopus.com/downloads – K.J. Feb 26 '17 at 00:40

3 Answers3

2

I have not used Octopus myself, but as far as I understand you have to make an HTTP POST request to an URL like this:

http://localhost:8080/api/projects/1/releases

In your request body you specify the same parameters as you would do it using the command line tool but you have to encode them as JSON.

benjiman
  • 3,888
  • 4
  • 29
  • 44
2

I had similar trouble with this myself.

In order to create a release, you must make a POST request to the Octo server.

https://myoctoserver:port/api/releases

Provide the following headers:

  • X-Octopus-ApiKey: API-XXXXXXXXXXXX
  • Content-Type: application/json

The body of the request must be JSON. Below is an example:

{
    "Version": "2017.02.25.183053" ,
    "ProjectId": "MyProject" ,
    "ChannelId": "DefaultOrOtherChannelId
}

The Version and ProjectId properties are required. Channel ID is optional. However, if you have more than one channel or if no channel in your project is marked as default then you must include ChannelId as well.

I hope this helps!


Curl Example

The sample below has been successful.

BODY='{"ProjectId":"'$PROJECT_ID'","ChannelId":"Channels-1","Version":"'$VERSION'","SelectedPackages":[{"StepName":"$STEP_NAME1","Version":"'$VERSION'"},{"StepName":"$STEP_NAME2","Version":"'$VERSION'"}]}'

curl -X POST --write-out %{http_code} --silent --output /dev/null -H "X-Octopus-ApiKey:$API_KEY" -H "Content-Type:application/json" -d $BODY "https://octopus.example.com/api/releases"

Notes

In order to find the ChannelId and ProjectId I had to query the Octopus database. The IDs will look something like Projects-1 or Channel-1

K.J.
  • 921
  • 7
  • 7
  • This returns an error: No package version was specified for the step 'Get Package'. Their API documentation is really poor... – mieliespoor Jun 01 '18 at 12:55
  • 1
    I have updated my post to include a curl example which I have used before. @mieliespoor The package is specified by both the version and the project ID. If you have a project _Foo_ with the version `0.5` then the json should look like `{"Version": "0.5", "ProjectId": "Foo", ChannelId: "Channels-1"}` – K.J. Jun 08 '18 at 14:43
0

Documentation for interfacing with the Octopus REST API leaves a lot to be desired: https://github.com/OctopusDeploy/OctopusDeploy-Api/wiki/Releases

I could never get it working through this approach, instead, I use the octo.exe command line utility to create releases:

octo create-release --project HelloWorld --version 1.0.3 --server http://octopus/ --apiKey API-ABCDEF123456

Octo.exe included as part of tentacle or server installs, Octopus also provide it as a seperate utility: http://octopusdeploy.com/downloads

ShaneC
  • 2,237
  • 2
  • 32
  • 53