Creating release using Octopus rest API - rest

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??

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.

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

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

Related

Deploy branch on Heroku via API [duplicate]

This question already has answers here:
Redeploy Heroku app without code changes
(7 answers)
Closed 4 years ago.
I have an application set up on heroku that is automatically deployed via GitHub. That setup is great and I don't want to change anything.
There is a use case now where I need to deploy the application from time to time without code changes (the build process fetches some recent data).
I can easily redeploy an app by going to the user interface and clicking "deploy a branch". However I would love to do this via an API. I could not find anything that helped achieve this in the Heroku Platform API Documentation.
I can create a Deployment via the GitHub deployment API but that doesn't seem to trigger a deployment on Heroku.
Any leads on how I can trigger a deployment for a specific app on Heroku?
Edit: I can't really make use of the answer Redeploy Heroku app without code changes as there is no answer that offers this functionality via an HTTP API.
Heroku doesn't currently have a public API for GitHub Sync. So you will need to use their Platform API to create a build.
GitHub gives you a tar.gz under the URL https://github.com/<organization>/<repository>/archive/master.zip (you need to pass an authorization token in the headers of course).
Using curl, you can do the following:
curl -n -v https://github.com/<organization>/<repository>/archive/master.zip
That URL will be a redirection to a URL on GitHub authenticated to allow the download. Reuse that URL to create an Heroku build:
curl -n -X POST https://api.heroku.com/apps/<app name>/builds \
-d '{
"source_blob": {
"url": "<the URL fetched before>",
"version": "<the version of the code you're trying to deploy>"
}
}' \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3"
That will trigger a new build, downloading the code from GitHub. Effectively doing the same as GitHub Sync internally does.
You can also see this tutorial: https://devcenter.heroku.com/articles/build-and-release-using-the-api

running a rundeck job from a rest api

I would like to allow anyone to trigger a job I've created in Rundeck.
I can't understand from the API documentation how to do that.
Any one knows, and can give simple examples (my understanding of the subject is minimal to none)?
What I've found is of the sort:
POST /api/1/job/[ID]/run
In order to use the Rundeck API, you need to authenticate first.
Authentication can be done in two different ways:
Using a Token
Using a username and a password
Here is an example of running a Rundeck job using its API (Token based authentication)
curl -X POST http://rundeck_server:port/api/19/job/87bdc26ce-9893-49bd-ad7a-97f4c4a39196/run?authtoken=AVy8jZdcpTYOyPcOVbfcfOQmB6b92zRu --header "Content-Type:text/xml"
Explanation:
19: the API version or Rundeck installation version (19 matchs
Rundeck 2.8.2)
87bdc26ce-9893-49bd-ad7a-97f4c4a39196: Job UUID
run: Runs a job
PS: To obtain an API Token, you must first log in to the Rundeck GUI using a user account. Click on your username in the header of the page, and you will be shown your User Profile page. From this page you can manage your API Tokens.
To update the answer above, this is an example of running a job and feeding it arguments
You will need to replace hostname/API version/job UID/token
Also the current version can be used with JSON only
curl -X POST https://rundeck-hostname.com/api/41/job/7087d3b7-e454-4983-abd5-a211d21d6f27/run?authtoken=[redacted] -H "Accept: application/json" -H "Content-Type: application/json" -d '{
"options": {
"optionName":"optionValue",
}
}
'
And if you need additional arguments for running a job you can find the updated documentation at https://docs.rundeck.com/docs/api/rundeck-api.html#running-a-job

Can I download Bamboo built artifacts using Bamboo Rest - API?

This page states:
Bamboo's REST APIs provide the following capabilities:
Retrieve the artifacts for a build.
and here I see the documentation:
http://myhost.com:8085/bamboo/rest/api/latest/plan/{projectKey}-{buildKey}/artifact
[GET]
When I try this link with the bamboo server I have, like:
https://my.bamboo.server/rest/api/latest/plan/MY-PLAN/artifact
All I get is:
<artifacts expand="artifacts">
<link href="http://my.bamboo.server/rest/api/latest/plan/MY-PLAN/artifact" rel="self"/>
<artifacts start-index="0" max-result="0" size="0"/>
</artifacts>
So am I understanding the REST documentation completely wrong, or is there something wrong possibly with MY-PLAN and this link is supposed to provide me a war file as I expect?
I'm afraid you are misunderstanding the REST documentation; by "Retrieve the artifacts for a build", it means "retrieves information about the build artifacts defined for a given plan". As you have already seen, all you get back is an XML or JSON document describing the artifacts defined.
If you want to download an actual build artifact, you'll need to write a script that uses /rest/api/latest/result/ to get the latest successful build info and, from that, form an actual download link to the artifact.
There are some issues related to your question: https://jira.atlassian.com/browse/BAM-11706
and BAM-16315 (which was deleted, because it contained customer details)
Here is the rest api documentation
https://docs.atlassian.com/atlassian-bamboo/REST/latest
Search for "/latest/result" documentation
http://myhost.com:8085/rest/api/latest/result/{projectKey}-{buildKey}-{buildNumber : ([0-9]+)|(latest)} [GET]
Example xml request
https://bamboo.server.com/rest/api/latest/result/projectKey-buildKey-buildNumber?expand=artifacts
Example json request
https://bamboo.server.com/rest/api/latest/result/projectKey-buildKey-buildNumber.json?expand=artifacts
Parse the artifacts node in the response. Each artifact should have an href property.
Pass the href to curl to download the artifact. You will probably need to setup a Bamboo token for rest api authentication.
Example curl request
curl -X GET -H "Authorization: Bearer ${BAMBOO_TOKEN}" $ARTIFACT_HREF
Spent a long time looking for this answer. Ended up having to piece together information and here is what I got. As #oallauddin mentions above, you need to get the url of the file from the xml.
curl -H "Authorization: Bearer <KEY>" https://bamboo.server.com/rest/api/latest/result/projectKey-buildKey-buildNumber?expand=artifacts
Alternative you can get it as json format
curl -H "Authorization: Bearer <KEY>" https://bamboo.server.com/rest/api/latest/result/projectKey-buildKey-buildNumber.json?expand=artifacts
I think where a lot of people are getting stuck is trying to use the Authorization header to download it after. BAM-20764 shows that this is NOT possible. You have to remove the header and use basic authentication with -u. Not both. Only the -u by itself.
curl -u username:password https://bamboo.server.com/browse/projectKey-build-Key-buildNumber/artifact/shared/<ARTIFACT_NAME>/<filename> --remote-name
The --remote-name/-O flag or --remote-header-name/-J is preferred here if you want to download the file with the default original name.
You've the link
<link href="http://my.bamboo.server/rest/api/latest/plan/MY-PLAN/artifact" rel="self"/>
Using curl you can download the artifact.
curl --user ${username}:{password} http://my.bamboo.server/rest/api/latest/plan/MY-PLAN/artifact

Is there a REST endpoint to kick off a Bamboo build?

I am trying to see how I might use wget or curl to kick off a Bamboo plan's build. I looked at their REST API docs and it doesn't seem to be an exposed endpoint. Is this possible or does Bamboo discourage REST-based builds?
Yes, it can be done. POST to the build queue service: https://developer.atlassian.com/server/bamboo/bamboo-rest-resources/#BambooRESTResources-BuildQueueService
You may use curl to trigger a build like below:
curl -X POST --user admin:admin http://host:8085/rest/api/latest/queue/PLAN-KEY?os_authType=basic

Stop a TeamCity build via REST call

Is it possible to cancel a currently running build via REST API?
I've got an integration which fetches currently running builds, and I would like to terminate builds of a given type if they are failed. I know how to list the failing builds of a given type, how do I then pass the stop command?
Since TeamCity 8.1 it is possible to stop build using REST API:
curl -v -u user:password --request POST "http://localhost:7000/app/rest/buildQueue/<buildLocator>" --data "<buildCancelRequest comment='' readdIntoQueue='true' />" --header "Content-Type: application/xml"
Maybe not with the REST API, but if you look here (towards the bottom in the Comments section) there's an 'undocumented' feature that lets you do it over HTTP.
Not exactly the REST call you were looking for, but you can simply do an HTTP POST to:
http://teamcity.my.org/viewLog.html?buildTypeId=bt278&buildId=1352480#
Where:
buildTypeId is your project's id
buildId is the build number to stop
Obviously, you can only do this while the build is running.