> ## Documentation Index
> Fetch the complete documentation index at: https://infisical.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Buildkite sync

> Learn how to configure a Buildkite sync for Infisical.

A Buildkite Secret Sync pushes secrets from Infisical into the [Buildkite secrets](https://buildkite.com/docs/pipelines/security/secrets/buildkite-secrets) of a cluster, where the cluster's agents read them with `buildkite-agent secret get` or the `secrets` key of a pipeline step. Each Infisical secret becomes a Buildkite secret with the same key, unless you customize key names to add a prefix or suffix. You can also limit the synced secrets to selected pipelines in the cluster.

> [!NOTE]
>
> The Buildkite Secret Sync requires a [Buildkite app connection](https://infisical.com/docs/integrations/app-connections/buildkite.md). This guide walks you through creating a project-scoped app connection.

## Prerequisites

* A [project with secrets configured](https://infisical.com/docs/documentation/platform/secrets-mgmt/quick-starts/deliver-first-secret.md)
* The [maintainer](https://buildkite.com/docs/pipelines/security/clusters/manage#manage-maintainers-on-a-cluster) role on the cluster you plan to sync to, or the administrator role in its Buildkite organization

## Step 1: Create a Buildkite API access token

Infisical needs a Buildkite API access token that can read organizations, clusters, and pipelines, and read and write secrets.

**Step 1**

Log in to Buildkite, open the account menu in the top right, and select **Personal settings**. Then select **API Access Tokens**.

![Personal Settings Menu](https://mintlify.s3.us-west-1.amazonaws.com/infisical/images/app-connections/buildkite/buildkite-personal-settings.png)

**Step 2**

Select **New API Access Token**, and enter your password if Buildkite asks for it.

![New API Access Token](https://mintlify.s3.us-west-1.amazonaws.com/infisical/images/app-connections/buildkite/buildkite-new-api-access-token.png)

**Step 3**

Fill in the form:

* **Description**: A name that identifies the token, such as `infisical`
* **Credential Type**: **Token**
* **Organization Access**: The organizations that own the clusters you plan to sync to
* **Token Expiry**: How long the token stays valid; once it expires, syncs fail until you update the connection with a new token
* **REST API Scopes**: **READ** for **Organizations**, **Clusters**, and **Pipelines**, and **READ** and **WRITE** for **Secrets**
* **GraphQL API Access**: **Disabled**, because Infisical uses only the REST API

Then select **Create New API Access Token**.

![Create New API Access Token](https://mintlify.s3.us-west-1.amazonaws.com/infisical/images/app-connections/buildkite/buildkite-create-api-access-token.png)

**Step 4**

Copy the token and store it securely. Buildkite shows it only once.

## Step 2: Set up the sync in Infisical

> [!TIP]
>
> To create the sync using the API, use the Buildkite [Create](https://infisical.com/docs/api-reference/endpoints/secret-syncs/buildkite/create.md) endpoint.

**Step 1**

In your project, go to **Integrations** and open the **Secret Syncs** tab. Select **+ Add Sync**.

![Secret Syncs Tab](https://mintlify.s3.us-west-1.amazonaws.com/infisical/images/secret-syncs/general/secret-sync-tab.png)

Then, select the **Buildkite** sync.

![Select Buildkite](https://mintlify.s3.us-west-1.amazonaws.com/infisical/images/secret-syncs/buildkite/select-option.png)

**Step 2**

Under **Source**, choose which secrets to sync from Infisical:

* **Environment**: The project environment to retrieve secrets from
* **Secret Path**: The folder path to retrieve secrets from
* **Include secrets from all subfolders**: Also syncs the secrets in every folder beneath the path

> [!NOTE]
>
> Buildkite accepts a secret only if it meets these rules:
>
> * The key starts with a letter, contains only letters, numbers, and underscores (`_`), and doesn't start with `buildkite` or `bk` in any case
> * No other synced secret has the same key in a different case, because Buildkite treats `API_KEY` and `api_key` as the same key
> * The value is at most 32,767 bytes
>
> If a secret breaks one of these rules, the sync fails before it writes anything, with an error that names the secret. Secrets with an empty value aren't synced, because Buildkite doesn't accept an empty value.

> [!TIP]
>
> If you need to sync secrets from multiple folder locations, use [secret imports](https://infisical.com/docs/documentation/platform/secret-reference.md#secret-imports).

![Configure Source](https://mintlify.s3.us-west-1.amazonaws.com/infisical/images/secret-syncs/buildkite/configure-source.png)

Then select **Continue**.

**Step 3**

Under **Destination**, create or select the Buildkite app connection the sync will use, then choose the cluster that receives the secrets.

> [tab] Create a new app connection
>
> Under **Buildkite Connection**, select **Create Connection** in the dropdown, then fill in:
>
> * **Name**: A descriptive name for the connection; it must be slug-friendly
> * **Description** (optional): A note for future reference
> * **Method**: **API Token**, the only method the connection supports
> * **Buildkite API Access Token**: The token you copied when [creating a Buildkite API access token](#step-1-create-a-buildkite-api-access-token)
>
> Select **Connect to Buildkite**. Infisical returns you to the sync form with the new connection selected.
>
> > [!NOTE]
> >
> > This creates a connection scoped to the current project. To share the connection across other projects, [create it at the organization level](https://infisical.com/docs/integrations/app-connections/buildkite.md#step-2-create-the-app-connection) first, then select it here.

> [tab] Use an existing connection
>
> Under **Buildkite Connection**, select the app connection you'd like to use.

* **Organization**: The Buildkite organization that owns the cluster
* **Cluster**: The Buildkite cluster to sync secrets to
* **Pipelines (optional)**: The pipelines in the cluster that can read the synced secrets (if you select none, the sync doesn't set or change access policies)

  ![Configure Destination](https://mintlify.s3.us-west-1.amazonaws.com/infisical/images/secret-syncs/buildkite/configure-destination.png)

Then select **Continue**.

**Step 4**

Under **Initial Sync Behavior**, select **Overwrite Buildkite**, then select **Continue**.

> [!NOTE]
>
> Buildkite never returns the value of a secret through its API, so this sync can't import existing Buildkite secrets into Infisical. **Overwrite Buildkite** is the only option.

![Initial Sync Behavior](https://mintlify.s3.us-west-1.amazonaws.com/infisical/images/secret-syncs/buildkite/initial-sync-behavior.png)

**Step 5**

Under **Sync Options**, choose how secrets are synced:

* **Prevent secret deletion**: When enabled, Infisical adds and updates secrets in Buildkite but never deletes them; enable this if you manage some of the cluster's secrets outside of Infisical
* **Auto-sync on changes**: When enabled, secrets sync to Buildkite automatically as the source changes; turn it off to sync manually only
* **Customize key names**: Adds a prefix or suffix to every synced key, using `{{secretKey}}` for the original name and `{{environment}}` for the environment slug

> [!WARNING]
>
> A Buildkite cluster's secrets are shared by every pipeline in the cluster, so a sync can change secrets that were created outside Infisical. If you don't customize key names, the sync treats every secret in the cluster as one it manages:
>
> * If a Buildkite secret has the same key as an Infisical secret, the sync overwrites the Buildkite secret's value
> * If **Prevent secret deletion** is off, every Buildkite secret that isn't in Infisical is deleted
>
> With customized key names, the sync writes only keys with your prefix or suffix, and deletes only Buildkite secrets whose keys match it.
>
> Before the first sync, customize key names or keep **Prevent secret deletion** on. **Prevent secret deletion** is on by default when you create the sync in the UI, but off unless you set `disableSecretDeletion` when you create it through the API.

![Configure Sync Options](https://mintlify.s3.us-west-1.amazonaws.com/infisical/images/secret-syncs/buildkite/configure-sync-options.png)

Then select **Continue**.

**Step 6**

Give the sync a **Name** and an optional **Description**. The name must be slug-friendly.

![Sync Details](https://mintlify.s3.us-west-1.amazonaws.com/infisical/images/secret-syncs/buildkite/configure-details.png)

Then select **Continue**.

**Step 7**

Under **Set up failure alerts**, choose who hears about it when the sync fails after all of its retries. The [failure alert](https://infisical.com/docs/integrations/secret-syncs/overview#get-alerted-when-a-sync-fails) is on by default under **Alert on Sync Failure**, with an email to the project's admins. Select **Add channel** to also notify Slack, a webhook, or PagerDuty, or turn the alert off to skip this step.

![Failure Alerts](https://mintlify.s3.us-west-1.amazonaws.com/infisical/images/secret-syncs/buildkite/configure-alerts.png)

Then select **Continue**.

**Step 8**

Review your Buildkite Sync configuration, then select **Create Sync**.

![Review and Create](https://mintlify.s3.us-west-1.amazonaws.com/infisical/images/secret-syncs/buildkite/review-configuration.png)

> [!TIP]
>
> The sync is created. If **Auto-sync on changes** is enabled, it begins syncing secrets to Buildkite right away.

## FAQ

> [accordion] Which builds can read the synced secrets?
>
> If you select pipelines in the **Pipelines** field, only builds of those pipelines can read the secrets. The sync gives each secret it writes an [access policy](https://buildkite.com/docs/pipelines/security/secrets/buildkite-secrets/access-policies) that allows only those pipelines, and replaces any other policy the secret has.
>
> If you leave **Pipelines** empty, every build in the cluster can read the secrets, unless a secret has an access policy in Buildkite. The sync creates secrets without a policy and changes only the value of an existing secret, so it keeps a policy you add in Buildkite, or one it set while pipelines were selected.

> [accordion] What happens if I change only the case of a secret's key?
>
> Buildkite treats keys that differ only in case as the same key, so the sync deletes the old Buildkite secret and creates one with the new key. The sync fails without changing anything if the old secret can't be replaced:
>
> * The sync has no pipelines selected and the old secret has an access policy, which the new secret would lose
> * The sync can't delete the old secret, because its key doesn't match your customized key names or **Prevent secret deletion** is on
>
> To rename a secret with a policy, delete the old secret in Buildkite, let the sync create the new one, and add the policy to it.

> [accordion] Why does a sync of many secrets take several minutes?
>
> Buildkite limits how many API requests each user can make per minute, 50 by default, and the sync makes at least one request for every secret. When the sync reaches the limit, it waits for Buildkite to reset the limit and then continues. The sync can't tell which values changed, because Buildkite doesn't return them, so it writes every value on every sync.
>
> To find the limits for your organization, open **Settings** > **Quotas** in Buildkite.

## Next steps

> [card] [Buildkite](https://infisical.com/docs/integrations/app-connections/buildkite.md)
>
> Create an organization-level Buildkite connection to share across projects.

> [card] [Secret syncs](https://infisical.com/docs/integrations/secret-syncs/overview)
>
> Learn how secret syncs work and how to manage them.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.