Overview:
Typically, build data will disappear after a set amount of time, based on your organization's plan. But what if I need data that is outside of my organization's plan? The CircleCI v2 API contains endpoints that will help retrieve build data on a regular basis so you can keep records going forward.
Steps to Retrieve Data:
Retrieve a list of pipelines for a given project: Get all pipelines
Retrieve a list of workflows for a given pipeline by the pipeline ID: Get a pipeline’s workflows
Retrieve the workflow data by the workflow ID: Get a workflow by ID
Retrieve the jobs of a workflow by the workflow ID: Get a workflow’s jobs
Store the retrieved pipeline, workflow, and job data in your chosen data stores
Repeat steps as required with the
next_page_tokenresponse from step 1
To expedite to process, we would recommend performing these steps in a script that can be reused and modified to suit your needs.
Using the v3 API
If you are on CircleCI cloud, you can follow the same steps with the v3 API. A v2 pipeline is a v3 run, and v3 identifies projects, runs, workflows, and jobs by UUID instead of by slug.
Get the project ID:
GET /api/v3/projects?filter[org_id]=<org-id>List the runs for the project:
GET /api/v3/runs?filter[project_id]=<project-id>List the workflows for a run:
GET /api/v3/workflows?filter[run_id]=<run-id>List the jobs for a workflow:
GET /api/v3/jobs?filter[workflow_id]=<workflow-id>Repeat with
page.nextfrom each response, sent back aspage[cursor], untilpage.nextisnull
Send your personal API token as Authorization: Bearer <token>, and use curl -g when a URL contains [ ]. See the API v3 developer's guide for details. API v3 is not available on CircleCI server, so use the v2 steps there.
Limitations:
While this method may allow you to get build data that is outside of your retention period, it will not be able to get all build data for a project that is outside of your plan's retention period. This is why we recommend that users regularly retrieve their build data and store it securely.
Additional Resources:
CircleCI API Developer's Guide - CircleCI - Please see the v2 API developer's guide for relevant information, including prerequisites and rate limits
