Skip to content

Commit

Permalink
adding new bitbucket pulumi guide (#13784)
Browse files Browse the repository at this point in the history
* adding new bitbucket pulumi guide

* fixing linting error
  • Loading branch information
interurban authored Jan 10, 2025
1 parent 0a34b7b commit ebbaaa5
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 29 deletions.
39 changes: 21 additions & 18 deletions content/docs/iac/using-pulumi/continuous-delivery/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ aliases:
- /docs/guides/continuous-delivery/
- /docs/using-pulumi/continuous-delivery/
- /docs/iac/packages-and-automation/continuous-delivery/
- /docs/iac/packages-and-automation/continuous-delivery
---

Pulumi's approach to infrastructure as code is great for continuous delivery, because it uses source code to model
Expand All @@ -25,71 +24,75 @@ process that you have today. For example, doing code reviews via Pull Requests,
analysis tools, and running unit and integration tests as appropriate. It all "just works" for your cloud
infrastructure the same way it would for your application code.

Pulumi can easily integrate into any continuous integration/continuous delivery (CI/CD) system. If your CI/CD system isn't listed below or you are testing something new, see [adding support for CI/CD systems](/docs/using-pulumi/continuous-delivery/add-support-for-cicd-systems).
Pulumi can easily integrate into any continuous integration/continuous delivery (CI/CD) system. If your CI/CD system isn't listed below or you are testing something new, see [adding support for CI/CD systems](/docs/iac/using-pulumi/continuous-delivery/add-support-for-cicd-systems).

> Looking to troubleshoot failures related to running Pulumi in CI/CD? Check out our [CI/CD troubleshooting guide](/docs/using-pulumi/continuous-delivery/troubleshooting-guide).
> Looking to troubleshoot failures related to running Pulumi in CI/CD? Check out our [CI/CD troubleshooting guide](/docs/iac/using-pulumi/continuous-delivery/troubleshooting-guide).
<div class="supported-cicd-platforms">
<a href="/docs/using-pulumi/continuous-delivery/aws-code-services">
<a href="/docs/iac/using-pulumi/continuous-delivery/aws-code-services">
<img src="/logos/tech/ci-cd/aws-codedeploy.svg" alt="AWS Code Services">
<h4 class="no-anchor">AWS Code Services</h4>
</a>
<a href="/docs/using-pulumi/continuous-delivery/azure-devops">
<a href="/docs/iac/using-pulumi/continuous-delivery/azure-devops">
<img src="/logos/tech/ci-cd/azure-devops.svg" alt="Azure DevOps">
<h4 class="no-anchor">Azure DevOps</h4>
</a>
<a href="/docs/using-pulumi/continuous-delivery/circleci">
<a href="/docs/iac/using-pulumi/continuous-delivery/bitbucket">
<img src="/logos/tech/ci-cd/bitbucket.svg" alt="Bitbucket">
<h4 class="no-anchor">Bitbucket</h4>
</a>
<a href="/docs/iac/using-pulumi/continuous-delivery/circleci">
<img src="/logos/tech/ci-cd/circleci.svg" alt="CircleCI">
<h4 class="no-anchor">CircleCI</h4>
</a>
<a href="/docs/using-pulumi/continuous-delivery/codefresh">
<a href="/docs/iac/using-pulumi/continuous-delivery/codefresh">
<img src="/logos/tech/ci-cd/codefresh.svg" alt="Codefresh">
<h4 class="no-anchor">Codefresh</h4>
</a>
<a href="/docs/using-pulumi/continuous-delivery/github-actions">
<a href="/docs/iac/using-pulumi/continuous-delivery/github-actions">
<img src="/logos/tech/ci-cd/github-actions.svg" alt="GitHub Actions">
<h4 class="no-anchor">GitHub Actions</h4>
</a>
<a href="/docs/using-pulumi/continuous-delivery/gitlab-ci">
<a href="/docs/iac/using-pulumi/continuous-delivery/gitlab-ci">
<img src="/logos/tech/ci-cd/gitlab-ci.svg" alt="GitLab CI">
<h4 class="no-anchor">GitLab CI</h4>
</a>
<a href="/docs/using-pulumi/continuous-delivery/google-cloud-build">
<a href="/docs/iac/using-pulumi/continuous-delivery/google-cloud-build">
<img src="/logos/tech/ci-cd/google-cloud-build.png" alt="Google Cloud Build">
<h4 class="no-anchor">Google Cloud Build</h4>
</a>
<a href="/docs/using-pulumi/continuous-delivery/jenkins">
<a href="/docs/iac/using-pulumi/continuous-delivery/jenkins">
<img src="/logos/tech/ci-cd/jenkins.svg" alt="Jenkins">
<h4 class="no-anchor">Jenkins</h4>
</a>
<a href="/docs/using-pulumi/continuous-delivery/octopus-deploy">
<a href="/docs/iac/using-pulumi/continuous-delivery/octopus-deploy">
<img src="/logos/tech/ci-cd/octopus-deploy.svg" alt="Octopus Deploy">
<h4 class="no-anchor">Octopus Deploy</h4>
</a>
<a href="/docs/pulumi-cloud/deployments/">
<img src="/logos/brand/avatar-on-white.png" alt="Pulumi Deployments">
<h4 class="no-anchor">Pulumi Deployments</h4>
</a>
<a href="/docs/using-pulumi/continuous-delivery/pulumi-kubernetes-operator">
<a href="/docs/iac/using-pulumi/continuous-delivery/pulumi-kubernetes-operator">
<img src="/logos/tech/ci-cd/kubernetes.png" alt="Pulumi Kubernetes Operator">
<h4 class="no-anchor">Pulumi Kubernetes Operator</h4>
</a>
<a href="/docs/using-pulumi/continuous-delivery/teamcity">
<a href="/docs/iac/using-pulumi/continuous-delivery/teamcity">
<img src="/logos/tech/ci-cd/teamcity.svg" alt="JetBrains TeamCity">
<h4 class="no-anchor">JetBrains TeamCity</h4>
</a>
<a href="/docs/using-pulumi/continuous-delivery/spinnaker">}}">
<a href="/docs/iac/using-pulumi/continuous-delivery/spinnaker">}}">
<img src="/logos/tech/ci-cd/spinnaker.svg" alt="Spinnaker">
<h4 class="no-anchor">Spinnaker</h4>
</a>
<a href="/docs/using-pulumi/continuous-delivery/travis">
<a href="/docs/iac/using-pulumi/continuous-delivery/travis">
<img src="/logos/tech/ci-cd/travis-ci.svg" alt="TravisCI">
<h4 class="no-anchor">TravisCI</h4>
</a>
</div>

> Pulumi can also bridge results from your CI/CD system with GitHub, surfacing the results of stack updates
> on GitHub pull requests. See the [Pulumi GitHub App](/docs/using-pulumi/continuous-delivery/github-app/) for more information.
> on GitHub pull requests. See the [Pulumi GitHub App](/docs/iac/using-pulumi/continuous-delivery/github-app/) for more information.
### Configuration and Secrets

Expand All @@ -114,5 +117,5 @@ to use one branch-per-[stack](/docs/concepts/stack/). This allows you to control
using your usual commit, code review, and approval process, such as GitHub pull requests.

If you are using GitHub pull requests to trigger updates, you will likely want to use the
[Pulumi GitHub App](/docs/using-pulumi/continuous-delivery/github-app/). This gives you interactive infrastructure change previews
[Pulumi GitHub App](/docs/iac/using-pulumi/continuous-delivery/github-app/). This gives you interactive infrastructure change previews
inside of your Pull Request, making it easier to see, review, and comment on any changes before a deployment occurs.
100 changes: 100 additions & 0 deletions content/docs/iac/using-pulumi/continuous-delivery/bitbucket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
title_tag: "Using Bitbucket Pipelines | CI/CD"
meta_desc: This page details how to use Bitbucket Pipelines to manage deploying staging and production stacks based on commits to specific Git branches.
title: Bitbucket Pipelines
h1: Pulumi CI/CD with Bitbucket Pipelines
meta_image: /images/docs/meta-images/docs-meta.png
menu:
iac:
name: Bitbucket Pipelines
parent: iac-using-pulumi-cicd
weight: 3
---

[Bitbucket Pipelines](https://support.atlassian.com/bitbucket-cloud/docs/get-started-with-bitbucket-pipelines/) is an CI/CD service built into Bitbucket Cloud. It allows you to build, test, and deploy your code automatically to your Pulumi staging and production stacks based on commits to specific Git branches.

This guide provides examples for integrating Bitbucket Pipelines with a [Pulumi AWS TypeScript project](/docs/iac/get-started/), but the outlined steps can be adapted for other projects in your favorite language.

## Prerequisites

- Sign up for a [Pulumi account](https://app.pulumi.com)
- Create a [Pulumi Access Token](https://app.pulumi.com/account/tokens)
- Install the [latest Pulumi CLI](/docs/install/)
- Create a [Bitbucket account](bitbucket.org) with Pipelines enabled
- Create a [new Bitbucket repository](https://support.atlassian.com/bitbucket-cloud/docs/create-a-git-repository/), and ensure you do not initialize it with a README

- Create a [new Pulumi project](/tutorials/pulumi-fundamentals/create-a-pulumi-project/) and [initialize it as a git repository](https://git-scm.com/docs/git-init)

## Setting up environment variables

To use Pulumi within Bitbucket Pipelines, there are a few environment variables you'll need to set.

The first is `PULUMI_ACCESS_TOKEN`, which is required to authenticate with Pulumi in order to
perform the `preview` or `update`.

Next, you will need to set environment variables specific to your cloud resource provider.
For example, if your stack is managing resources on AWS, you will need to set `AWS_ACCESS_KEY_ID` and
`AWS_SECRET_ACCESS_KEY`.

{{% notes type="info" %}}

Add these variables in Bitbucket to your **Repository settings > Repository variables**, ensuring you click on the **Secured** checkbox, as is a security best practice to mark any sensitive variables as protected in Bitbucket. You can learn more about how to protect environment variables by referencing their [variables and secrets](https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/) documentation.

{{% /notes %}}

## Bitbucket pipeline configuration

In Bitbucket, a CI/CD pipeline is defined in a yaml file labeled `.bitbucket-pipelines.yml`. This file must exist in the root of your repository and defines how Bitbucket Pipelines will build and deploy your Pulumi stack.

Here's an example configuration:

```yaml
# This is an example Bitbucket starter pipeline configuration
# Use a skeleton to build, test and deploy using manual and parallel steps
# -----
# You can specify a custom docker image from Docker Hub as your build environment.

image: atlassian/default-image:4

pipelines:
pull-requests:
'**':
- step:
script:
- if [ "${BITBUCKET_PR_DESTINATION_BRANCH}" != "main" ]; then printf 'target branch not main, skipping preview'; exit; fi
- step:
name: 'Run Pulumi Preview'
image: pulumi/pulumi-nodejs:latest
script:
- npm ci
- pulumi login
- pulumi stack select $STACK
- pulumi preview

branches:
main:
- step:
name: 'Run Pulumi Up'
image: pulumi/pulumi-nodejs:latest
script:
- npm ci
- pulumi login
- pulumi stack select $STACK
- pulumi up --yes

```

When working with Pulumi in Bitbucket Pipelines with Pulumi, you will need to specify when certain actions, like previews, are run.

```yaml
'**':
- step:
script:
- if [ "${BITBUCKET_PR_DESTINATION_BRANCH}" != "main" ]; then printf 'target branch not main, skipping preview'; exit; fi
```
This step and script ensures that the following Pulumi preview step only runs if the pull request is targeting the main branch. This avoids unnecessary previews for pull requests to other branches.
## Running the pipeline
Once the `.bitbucket-pipelines.yml` is committed, each push or pull request to the main branch of the repository will trigger the pipeline, automating the deployment of your infrastructure. You can monitor the pipeline status in the **Pipelines** tab in Bitbucket.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ menu:
iac:
name: CircleCI
parent: iac-using-pulumi-cicd
weight: 3
weight: 4
aliases:
- /docs/reference/cd-circleci/
- /docs/console/continuous-delivery/circleci/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ menu:
iac:
name: Codefresh
parent: iac-using-pulumi-cicd
weight: 4
weight: 5
aliases:
- /docs/reference/cd-codefresh/
- /docs/console/continuous-delivery/codefresh/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ menu:
iac:
name: GitHub Actions
parent: iac-using-pulumi-cicd
weight: 5
weight: 6
aliases:
- /docs/reference/cd-github-actions/
- /docs/console/continuous-delivery/github-actions/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ menu:
iac:
name: GitHub App
parent: iac-using-pulumi-cicd
weight: 6
weight: 7
aliases:
- /docs/reference/cd-github/
- /docs/console/continuous-delivery/github-app/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ menu:
iac:
name: GitLab Integration
parent: iac-using-pulumi-cicd
weight: 7
weight: 8
aliases:
- /docs/guides/continuous-delivery/gitlab-app/
- /docs/using-pulumi/continuous-delivery/gitlab-app/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ menu:
iac:
name: GitLab CI
parent: iac-using-pulumi-cicd
weight: 7
weight: 9
aliases:
- /docs/reference/cd-gitlab-ci/
- /docs/console/continuous-delivery/gitlab-ci/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ menu:
iac:
name: Google Cloud Build
parent: iac-using-pulumi-cicd
weight: 9
weight: 10
aliases:
- /docs/reference/cd-google-cloud-build/
- /docs/console/continuous-delivery/google-cloud-build/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ menu:
iac:
name: Jenkins
parent: iac-using-pulumi-cicd
weight: 10
weight: 11
usingpulumi:
parent: cont_delivery
weight: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ menu:
iac:
name: Octopus Deploy
parent: iac-using-pulumi-cicd
weight: 11
weight: 12
aliases:
- /docs/guides/continuous-delivery/octopus-deploy/
- /docs/using-pulumi/continuous-delivery/octopus-deploy/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ menu:
iac:
name: Spinnaker
parent: iac-using-pulumi-cicd
weight: 12
weight: 14
aliases:
- /docs/guides/continuous-delivery/spinnaker/
- /docs/using-pulumi/continuous-delivery/spinnaker/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ menu:
iac:
name: TeamCity
parent: iac-using-pulumi-cicd
weight: 14
weight: 15
aliases:
- /docs/guides/continuous-delivery/teamcity/
- /docs/using-pulumi/continuous-delivery/teamcity/
Expand Down
26 changes: 26 additions & 0 deletions static/logos/tech/ci-cd/bitbucket.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ebbaaa5

Please sign in to comment.