# Buildkite

{% hint style="info" %}
Cortex connects to many third-party vendors whose system interfaces frequently change. As a result, integration behavior or configuration steps may shift without notice. If you encounter unexpected issues, check with your system administrator or refer to the vendor's documentation for the most current information. Additionally, integration sync times vary and are subject to scheduling overrides and timing variance.
{% endhint %}

[Buildkite](https://buildkite.com/) is a continuous integration and delivery platform that enablers users to run fast, secure, and scalable pipelines on their own infrastructure.

Integrating Buildkite with Cortex allows you to:

* Pull in metrics about your builds and pipelines
* Create [Scorecards](#scorecards-and-cql) that track progress and drive alignment on projects involving your Buildkite pipelines

## How to configure Buildkite with Cortex

### Prerequisites

Before getting started:

* Create a [Buildkite API access token](https://buildkite.com/docs/apis/managing-api-tokens) with read-only permissions for pipelines and builds.
  * You must be a member of a Buildkite organization to generate and use an access token for it.

### Configure the integration in Cortex

1. In Cortex, navigate to the [Buildkite settings page](https://app.getcortexapp.com/admin/integrations/buildkite).
   * Click **Integrations** from the main nav. Search for and select **Buildkite**.
2. Configure the Buildkite integration form:
   * **API token**: Enter your Buildkite API token.
   * **Organizational slug**: Enter the slug for your Buildkite organization.
     * This can be found in your organization's Buildkite settings, or at the end of your Buildkite URL after navigating to **Pipelines**.
3. Click **Save**.

To modify the integration configuration, see [Modifying an existing integration configuration](/ingesting-data-into-cortex/integrations.md#modifying-an-existing-integration-configuration).

## How to connect Cortex entities to Buildkite

### Discovery

By default, Cortex will use the [Cortex tag](/ingesting-data-into-cortex/entities-overview/entities.md#cortex-tag) (e.g. `my-entity`) for your Buildkite pipeline. For example, if your Cortex tag is `my-pipeline`, then the corresponding pipeline tag in Buildkite should also be `my-pipeline`.

Cortex will also use the the GitHub, GitLab, Bitbucket, or Azure DevOps repository to connect entities to Buildkite pipelines. For example, if the GitHub repo associated with your Buildkite pipeline is `my-org/repo`, then entities in Cortex that also live in `my-org/repo` will populate with details from that pipeline.

### Editing the entity descriptor

You can add Buildkite pipelines to an entity by defining the pipeline slug or tags with one of the following blocks in the entity descriptor:

```yaml
x-cortex-ci-cd:
  buildkite:
    pipelines:
    - slug: my-buildkite-pipeline-slug-1
    - slug: my-buildkite-pipeline-slug-2
```

| Field  | Description                     | Required |
| ------ | ------------------------------- | :------: |
| `slug` | Slug for the Buildkite pipeline |   **✓**  |

```yaml
x-cortex-ci-cd:
  buildkite:
    tags:
    - tag: my-buildkite-tag-1
    - tag: my-buildkite-tag-2
```

| Field | Description                    | Required |
| ----- | ------------------------------ | :------: |
| `tag` | Tag for the Buildkite pipeline |   **✓**  |

The slug for your pipeline can be found in the Buildkite URL for a given pipeline (e.g., `https://buildkite.com//`).

## Using the Buildkite integration

#### Entity pages

Once the Buildkite integration is established, Cortex will automatically pull in pipeline data to an entity's page. You can access this data from the **CI/CD** page in the entity's side panel.

You can find a list of pipeline runs for each pipeline linked to a given entity on this page:

* Pipeline slug/tag
* Action (e.g. "scheduled build")
* Timestamp
* Branch
* State

The [state](https://buildkite.com/docs/pipelines/notifications#build-states) for a build will appear as a tag next to the pipeline slug/tag (e.g. `canceled`, `passed`, or `failed`).

### Scorecards and CQL

With the Buildkite integration, you can create Scorecard rules and write CQL queries based on Buildkite pipelines.

See more examples in the [CQL Explorer](https://app.getcortexapp.com/admin/cql-explorer) in Cortex.

<details>

<summary>Check if Buildkite pipeline(s) are set</summary>

Check if entity has registered Buildkite pipelines in its entity descriptor.

**Definition:** `buildkite (==/!=) null`

**Example**

For a Scorecard focused on production readiness, you can pull in data from Buildkite to make sure that entities belong to a CI/CD pipeline.

```
buildkite != null
```

</details>

<details>

<summary>Get Buildkite build(s)</summary>

Gets pipelines and builds that meet given filter criteria.

* Build criteria:
  * Branch
  * Commit
  * Created at
  * ID
  * Message
  * Number
  * Pipeline
  * State
* Pipeline criteria:
  * Description
  * Git repository
  * ID
  * Name
  * Slug
  * Tags

States include CANCELED, PASSED, and FAILED.

**Definition**: `buildkite.builds()`

**Example**

If you're building a Scorecard with an emphasis on operational maturity, you could set a rule to make sure not only that entities belong to a pipeline, but that the pipeline is functioning as expected.

```
buildkite.builds(states["passed"]).length >=1
```

</details>

<details>

<summary>Get Buildkite pipelines</summary>

Get all Buildkite pipelines associated with the entity: Description, Git repository, ID, Name, Slug, Tags.

**Definition**: `buildkite.pipelines()`

**Example**

A production readiness Scorecard can use this expression in a rule confirming that there are pipelines linked to a specific repository:

```
buildkite.pipelines().any((pipeline) => pipeline.gitRepository = )
```

</details>

### View integration logs <a href="#still-need-help" id="still-need-help"></a>

## Still need help?[​](https://docs.cortex.io/docs/reference/integrations/aws#still-need-help) <a href="#still-need-help" id="still-need-help"></a>

The following options are available to get assistance from the Cortex Customer Engineering team:

* **Email**: <help@cortex.io>, or open a support ticket in the in app Resource Center
* **Slack**: Users with a connected Slack channel will have a workflow added to their account. From here, you can either @CortexTechnicalSupport or add a `:ticket:` reaction to a question in Slack, and the team will respond directly.

Don’t have a Slack channel? Talk with your Customer Success Manager.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cortex.io/ingesting-data-into-cortex/integrations/buildkite.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
