Xcode Cloud API - documentation

Hi,

I'm writing here because I'm having some difficulties with the Xcode Cloud API.

I'm trying to start a build on Xcode Cloud through API on a specific branch.

I have tried to structure the body of the requests using the sourceBranchOrTag relationship, but I keep running into 409/422 HTML codes.

Currently this is my body:

{
    "data": {
        "type": "ciBuildRuns",
        "attributes": {},
        "relationships": {
            "workflow": {
                "data": {
                    "type": "ciWorkflows",
                    "id": WORKFLOW_ID
                }
            },
            "sourceBranchOrTag": {
                "data": {
                        "type": "CiGitRefKind",
                        "id": "develop",
                        "attributes": {
                            "kind": "branch"
                        }    
                }
            }
        }
    }
}

I have tried different combinations, but to no avail.

Looking at the documentation there is no clear way on how to structure the scmGitReferences object required in the body, does anyone have an example of a body like this one?

Extra: Also the documentation is really bad at explaining how query parameters works. Some more practical examples would help a ton. (e.g. filtering the list of builds of a workflow by executionProgress=RUNNING seems impossible?)

Thanks for your time and have a great day,

Davide

Replies

I think you need to look thru all the scmGitReferences to find the branch one from previous run for your branch.

It looks like    "canonicalName": "refs/heads/stage" for my branch stage.

{
 "data": {
  "type": "scmGitReferences",
  "id": "6ce1ce69-c00b-46d1-8453-887f23b8JJHS",
  "attributes": {
   "name": "stage",
   "canonicalName": "refs/heads/stage",
   "isDeleted": false,
   "kind": "BRANCH"
  },
  "links": {
   "self": "https://api.appstoreconnect.apple.com/v1/scmGitReferences/6ce1ce69-c00b-46d1-8453-887f23b8JJHS"
  }
 },
 "included": {}
}

This works for me

{
      "sourceBranchOrTag": {
        "data": {
         "type": "scmGitReferences",
         "id": "6ce1ce69-c00b-46d1-8453-887f23b8JJHS"
        }
      },
      workflow: {
        data: {
          type: "ciWorkflows",
          id: `${branch === 'stage' ? stageWorkflow : prodWorkflow}`
        }
      }
    };

How did I get the IDs?

Start with your workflow:

  const gitRef = await readAll('https://api.appstoreconnect.apple.com/v1/ciWorkflows/59D98329-2C36-4A9D-A657-B32EJUNK/relationships/repository');  console.log(JSON.stringify(gitRef, null, 2));

Then look at gitReferences:  const gitrepo = await readAll('https://api.appstoreconnect.apple.com/v1/scmRepositories/02604932-197a-48a0-b182-fa78f97JUNK/relationships/gitReferences');  console.log(JSON.stringify(gitrepo, null, 2));

then find the right one -- to see in detail:  const reference = await readAll('https://api.appstoreconnect.apple.com/v1/scmGitReferences/6ce1ce69-c00b-46d1-8453-887f23b8JJHS');  console.log(JSON.stringify(reference, null, 2));

Thank you!!