# Using BitBucket Pipelines

You can build your custom Continuous Deployment jobs using BitBucket Pipelines and [Bolt APIs](/app-help/~/changes/rDjfrwa4QH3nWWrOItTq/documentation/bolt/bolt-api.md).

{% hint style="info" %}
**To use this feature it is required to have a production environment configured in Paradime.**

**ℹ️** [**Check our setup guide here based on your data warehouse provider**](/app-help/~/changes/rDjfrwa4QH3nWWrOItTq/documentation/settings/connections/scheduler-environment.md)**.**
{% endhint %}

## Create a CD Bolt schedule

To start create a new Bolt schedule and make sure to add the `deferred_schedule` configuration. Depending on your intended behavior you can choose to defer to another production job or defer back to the last CD run.

{% hint style="info" %}
The **`deferred_schedule_name`** set in the configuration should have at least one successful run available, so that Paradime can pick the manifest.json for state comparison.
{% endhint %}

### Example schedule

```yaml
...
  - name: continuous_deployment_run # the name of your CD job
    deferred_schedule:
      enabled: true # true to enabled this Turbo CI job to run on pull request
      deferred_schedule_name: continuous_deployment_run #the name of the bolt schedule where the CD job will look for the most recent successful run manifest.json for state comparison
    schedule: "OFF" # set the schedule configuration to not run on a schedule (to be used for PR only)
    environment: production #the environment used to run the schedule -> this is always production
    commands:
      - dbt run --select state:modified+ #the dbt™️ command you want to run after the pull request is merged
    owner_email: "john@acme.io" #the email of the CD job owner_email
...
```

## Generate API keys and find you workspace token

{% hint style="warning" %}
**API keys are generate at a workspace level.**
{% endhint %}

To be able to trigger Bolt using the API, you will first need to generate API keys for your workspace. Got to account settings and generate your API keys, make sure to save in your password manager:

* API key
* API secret
* API Endpoint

You will need this later when setting up the secrete in BitBucket pipelines.

{% content-ref url="/pages/ZsR10m0IstITtXbGOX9C" %}
[API Keys](/app-help/~/changes/rDjfrwa4QH3nWWrOItTq/developers/generate-api-keys.md)
{% endcontent-ref %}

## Create an BitBucket Pipeline

Now you will need to create a new `bitbucket-pipelines.yml` file in your dbt™️ repository. Copy the code block below and enter the values required.

<details>

<summary>Example BitBucket pipelines configuration file</summary>

{% code title="bitbucket-pipelines.yml" lineNumbers="true" %}

```yaml
# Specify the base Docker image to use for all pipeline steps
image: python:3.11

# Define reusable pipeline steps
definitions:
 steps:
   # Create a reusable step template using YAML anchor (&)
   - step: &paradime-continuous-deployment
       # Name of this pipeline step for identification
       name: Paradime Continuous Deployment
       
       # Commands to execute in this step
       script:
         # Export required Paradime environment variables
         - export PARADIME_API_KEY=$PARADIME_API_KEY
         - export PARADIME_API_SECRET=$PARADIME_API_SECRET
         - export PARADIME_API_ENDPOINT=$PARADIME_API_ENDPOINT
         
         # Install Paradime Python SDK
         - pip install paradime-io==4.7.1  # Check for latest version of the Paradime Python SDK on https://github.com/paradime-io/paradime-python-sdk/releases
         
         # Run the Paradime bolt schedule and wait for completion
         - paradime bolt run "continuous_deployment_run" --wait
       
       # Specify compute resources for this step
       size: 2x  # Double the default resources
       
       # Set maximum execution time in minutes
       max-time: 60

# Define when and how pipelines should run
pipelines:
 branches:
   # This pipeline will only run when changes are pushed to the main branch
   main:  
     - step:
         # Reference the template step defined above using YAML alias (*)
         <<: *paradime-continuous-deployment
         
         # Define environment variables needed for this step
         # These should be configured in Bitbucket repository settings
         variables:
           API_KEY: PARADIME_API_KEY      # API key for Paradime authentication
           API_SECRET: PARADIME_API_SECRET # API secret for Paradime authentication
           API_ENDPOINT: PARADIME_API_ENDPOINT # Paradime API endpoint URL
```

{% endcode %}

</details>

### Add the API keys and Credential in the BitBucket Pipeline variables

Finally you need to add the API key and credentials generated in the [previous step](#generate-api-keys-and-find-you-workspace-uid) in BitBucket Pipelines.

Set the corresponding values using your credentials for the variable names:

* `PARADIME_API_KEY`
* `PARADIME_API_SECRET`
* `PARADIME_API_ENDPOINT`

{% @arcade/embed flowId="F07biP3yTQk37Ntyc095" url="<https://app.arcade.software/share/F07biP3yTQk37Ntyc095>" %}


---

# 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.paradime.io/app-help/~/changes/rDjfrwa4QH3nWWrOItTq/documentation/bolt/ci-cd/continuous-deployment-with-bolt/using-bitbucket-pipelines.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.
