Bitbucket Pipelines

This walkthrough shows you how to use CloudTruth parameters with Bitbucket Pipelines.

Prerequisites

Provide Bitbucket Pipelines CloudTruth Access

You can get started with Bitbucket using a starter pipeline template.

Add your generated CloudTruth API access token as a Bitbucket repository variable namedCLOUDTRUTH_API_KEY in your Repository settings > Pipelines > Repository variables. This allows the Bitbucket repository to securely access parameters stored in CloudTruth across all deployment environments.

Configure a Bitbucket Pipeline with CloudTruth Parameters

Using the CloudTruth CLI

You can install the CLI with the following code snippet as part of a Bitbucket step in bitbucket-pipelines.yml. This will install the latest supported version and also verify the CLI is installed correctly by printing the version.

We then use the CloudTruth CLI run command to print only CloudTruth variables that can now be accessed in your pipeline.

image: atlassian/default-image:2
pipelines:
default:
- step:
name: 'Install CloudTruth CLI:'
script:
- (curl -sL https://github.com/cloudtruth/cloudtruth-cli/releases/latest/download/install.sh || wget -qO- https://github.com/cloudtruth/cloudtruth-cli/releases/latest/download/install.sh) | sh
- cloudtruth -V
- cloudtruth run -i none -- printenv

Running this pipeline will install the CloudTruth CLI and print parameter values retrieved from CloudTruth.

Passing CloudTruth parameters across Bitbucket Pipeline steps

You can use variables across Bitbucket pipeline steps by creating an export formatted environment file and storing the file using Bitbucket artifacts. This snippet uses the CloudTruth CLI to create an export dotenv file with values pulled from CloudTruth.

- cloudtruth parameter export shell --export > dotenv
# Passes environement variables between stages
artifacts:
- dotenv

Using CloudTruth parameters across Bitbucket Pipeline steps

In future pipeline steps you can source the dotenv artifact. The command source dotenv will execute the dotenv export allowing you to reference the variables in downstream stages without the CloudTruth CLI.

- step:
name: 'CloudTruth Variables Deployment to Staging'
deployment: staging
script:
- echo "Test CloudTruth Staging Step"
- source dotenv
- printenv

The complete bitbucket-pipelines.yml passing variables between steps.

image: atlassian/default-image:2
pipelines:
default:
- step:
name: 'Install CloudTruth CLI:'
script:
- (curl -sL https://github.com/cloudtruth/cloudtruth-cli/releases/latest/download/install.sh || wget -qO- https://github.com/cloudtruth/cloudtruth-cli/releases/latest/download/install.sh) | sh
- cloudtruth -V
- cloudtruth run -i none -- printenv
- cloudtruth parameter export shell --export > dotenv
# Passes environement variables between stages
artifacts:
- dotenv
- step:
name: 'CloudTruth Variables Deployment to Staging'
deployment: staging
script:
- echo "Test CloudTruth Staging Step"
- source dotenv
- printenv

Running this pipeline will install the CloudTruth CLI and print the parameter values across multiple steps.