Create build

2 minute read

POST /organizations/{organization_uuid}/projects/{project_uuid}/builds

Creates a new build based on the specified project (project_uuid) and the branch name (ref) provided.

If you specify an old commit SHA (or just one that’s already been processed by CodeShip), it has the same effect as the Restart Build endpoint, except you don’t need to first find the build if you already know the SHA.

  • The branch name must have the format heads/master similar to the GitHub’s refs format. If you just send in master or similar, it will not result in a new build.

  • If you’re restarting an old Basic build, it may not be readily visible in the web console (depending on your view). When a Basic build is restarted, it’s not pulled to the top of the list, so you’d need to go back in the list to find the original one.

  • A successful request returns a 202 which indicates the request was successfully received, however this does not guarantee the build will actually run.

Authentication

  • OAuth2

OAuth2 scopes

  • build.write

Path parameters

Field name Type Required

organization_uuid

string

X

project_uuid

string

X

Headers

Field name Type Required

Authorization

string

X

Request body schema

  • Content type: application/json

  • Response schema type: object

Field name Type Required

ref

string

X

commit_sha

string

Request body example

{ "ref": "heads/master", "commit_sha": "5927b8c40deecc656138f61b7e0d77e9cca835ac" }

Responses

Code Datatype

202

No response body

400

Error

401

Error

403

Error

404

Error

500

Error

Code examples

cURL
Go
Java
Node
PHP
Python
Ruby
C#
curl --request POST \ --url https://api.codeship.com/v2/organizations/721cea10-b6a5-0104-5b93-5240c481c5a2/projects/019f9bcc-ce4b-4179-a533-c3995f4b6161/builds \ --header 'authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9' \ --header 'content-type: application/json' \ --data '{"ref":"heads/master","commit_sha":"5927b8c40deecc656138f61b7e0d77e9cca835ac"}'
package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://api.codeship.com/v2/organizations/721cea10-b6a5-0104-5b93-5240c481c5a2/projects/019f9bcc-ce4b-4179-a533-c3995f4b6161/builds" payload := strings.NewReader("{\"ref\":\"heads/master\",\"commit_sha\":\"5927b8c40deecc656138f61b7e0d77e9cca835ac\"}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("authorization", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9") req.Header.Add("content-type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) }
OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, "{\"ref\":\"heads/master\",\"commit_sha\":\"5927b8c40deecc656138f61b7e0d77e9cca835ac\"}"); Request request = new Request.Builder() .url("https://api.codeship.com/v2/organizations/721cea10-b6a5-0104-5b93-5240c481c5a2/projects/019f9bcc-ce4b-4179-a533-c3995f4b6161/builds") .post(body) .addHeader("authorization", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9") .addHeader("content-type", "application/json") .build(); Response response = client.newCall(request).execute();
var http = require("https"); var options = { "method": "POST", "hostname": "api.codeship.com", "port": null, "path": "/v2/organizations/721cea10-b6a5-0104-5b93-5240c481c5a2/projects/019f9bcc-ce4b-4179-a533-c3995f4b6161/builds", "headers": { "authorization": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9", "content-type": "application/json" } }; var req = http.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function () { var body = Buffer.concat(chunks); console.log(body.toString()); }); }); req.write(JSON.stringify({ ref: 'heads/master', commit_sha: '5927b8c40deecc656138f61b7e0d77e9cca835ac' })); req.end();
<?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.codeship.com/v2/organizations/721cea10-b6a5-0104-5b93-5240c481c5a2/projects/019f9bcc-ce4b-4179-a533-c3995f4b6161/builds", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "{\"ref\":\"heads/master\",\"commit_sha\":\"5927b8c40deecc656138f61b7e0d77e9cca835ac\"}", CURLOPT_HTTPHEADER => array( "authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9", "content-type: application/json" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
import http.client conn = http.client.HTTPSConnection("api.codeship.com") payload = "{\"ref\":\"heads/master\",\"commit_sha\":\"5927b8c40deecc656138f61b7e0d77e9cca835ac\"}" headers = { 'authorization': "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9", 'content-type': "application/json" } conn.request("POST", "/v2/organizations/721cea10-b6a5-0104-5b93-5240c481c5a2/projects/019f9bcc-ce4b-4179-a533-c3995f4b6161/builds", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
require 'uri' require 'net/http' url = URI("https://api.codeship.com/v2/organizations/721cea10-b6a5-0104-5b93-5240c481c5a2/projects/019f9bcc-ce4b-4179-a533-c3995f4b6161/builds") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(url) request["authorization"] = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9' request["content-type"] = 'application/json' request.body = "{\"ref\":\"heads/master\",\"commit_sha\":\"5927b8c40deecc656138f61b7e0d77e9cca835ac\"}" response = http.request(request) puts response.read_body
var client = new RestClient("https://api.codeship.com/v2/organizations/721cea10-b6a5-0104-5b93-5240c481c5a2/projects/019f9bcc-ce4b-4179-a533-c3995f4b6161/builds"); var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); request.AddHeader("authorization", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9"); request.AddParameter("application/json", "{\"ref\":\"heads/master\",\"commit_sha\":\"5927b8c40deecc656138f61b7e0d77e9cca835ac\"}", ParameterType.RequestBody); IRestResponse response = client.Execute(request);