Using GitLab Pipelines

You can build your custom Continuous Deployment jobs using GitLab Pipelines and Bolt APIs.

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.

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.

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.

Example schedule

...
  - 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: hourly_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

API keys are generate at a workspace level.

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

  • Workspace token

You will need this later when setting up the secret in GitLab pipelines.

pageGenerate API keyspageCompany & Workspace token

Create a GitLab Pipeline

GitLab merged results pipelines is a feature available only on Tier: Premium, Ultimate. Make sure to enable merge results pipelines in GitLab before proceeding to next step.

Now you will need to create a new .gitlab-ci.yml file at the root of your project your dbt™️ repository. Copy the code block below and enter the values required.

Example GitLab pipelines configuration file
.gitlab-ci.yml
# Paradime variables
variables:
  SCHEDULE_NAME: <the schedule name set in Paradime> #example turbi_ci_job
  API_URL:  <the api endpoint generated in the previous step> #example https://api.paradime.io/api/v1/uany7ed234ovarzx/graphql
  WORKSPACE_TOKEN: <the workspace token generated in the previous step> #example 8p232d9mo4cvea9w
  BASE_PARADIME_BOLT_URL: 'https://app.paradime.io/bolt/run_id/'
  
stages:
  - paradime_continuous_deployment

workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_EVENT_TYPE == "merged"'

trigger_bolt_run:
  stage: paradime_continuous_deployment
  image: ubuntu:latest
  script:
    - apt-get update && apt-get install -y curl jq # Install curl and jq before using them
    - |
      response=$(curl -s -X POST \
      -H "Content-Type: application/json" \
      -H "X-API-KEY: $API_KEY" \
      -H "X-API-SECRET: $API_SECRET" \
      -d "{
        \"query\": \"mutation trigger { triggerBoltRun(scheduleName: \\\"${SCHEDULE_NAME}\\\") { runId } }\"
      }" "${API_URL}")
      echo "$response"

      runId=$(echo "$response" | jq -r '.data.triggerBoltRun.runId')
      if [ "$runId" == "null" ]; then
        exit 1
      fi

      echo "$runId" > runID.tmp # Save runId to a file to be read in the next step
      
    - |
      runId=$(cat runID.tmp)
      
      echo "${BASE_PARADIME_BOLT_URL}${runId}?workspaceToken=${WORKSPACE_TOKEN}"
      while :
      do
        response=$(curl -s -X POST \
        -H "Content-Type: application/json" \
        -H "X-API-KEY: ${API_KEY}" \
        -H "X-API-SECRET: ${API_SECRET}" \
        -d "{
          \"query\": \"{ boltRunStatus(runId: ${runId}) { state } }\"
        }" "${API_URL}")
        echo $response
        
        state=$(echo "$response" | jq -r '.data.boltRunStatus.state')
        
        if [ "$state" != "RUNNING" ]; then
          if [ "$state" != "SUCCESS" ]; then
            exit 1
          fi
          exit 0
        fi
        
        sleep 10
      done
  # Define a timeout for this job
  timeout: 60 minutes

Add the API key and Credential in the GitLab variables

Finally you need to add the API key and credentials generated in the previous step in GitLab CI/CD pipelines.

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

  • API_KEY

  • API_SECRET

Last updated