Skip to content

Instantly share code, notes, and snippets.

@dane-stevens
Last active November 4, 2019 11:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dane-stevens/054d3d54ee97d36856429ccdcfdb5e0b to your computer and use it in GitHub Desktop.
Save dane-stevens/054d3d54ee97d36856429ccdcfdb5e0b to your computer and use it in GitHub Desktop.
Sample Bitbucket Pipelines Config
options:
# Enable docker for the Pipeline
docker: true
pipelines:
branches:
master:
- step:
name: Build app for Production (create-react-app)
image: mhart/alpine-node:10
caches:
- node
script:
# Install Dependencies
- npm install
# Run our Tests
- npm run test
# Package App for Production
- npm run build
artifacts:
# Pass the "build" Directory to the Next Step
- build/**
- step:
name: Build Docker Image
script:
# NOTE: Set $DOCKER_HUB_USERNAME and $DOCKER_HUB_PASSWORD as environment SECRETS in Bitbucket repository settings
# Use $BITBUCKET_COMMIT to tag our docker image
- export IMAGE_NAME=<docker-username>/<docker-image>:$BITBUCKET_COMMIT
# Build the Docker image (this will use the Dockerfile in the root of the repo)
- docker build -t $IMAGE_NAME .
# Authenticate with the Docker Hub registry
- docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD
# Push the new Docker image to the Docker registry
- docker push $IMAGE_NAME
- step:
# trigger: manual
name: Deploy to Kubernetes
image: atlassian/pipelines-kubectl
script:
# NOTE: $KUBECONFIG is secret stored as a base64 encoded string
# Base64 decode our kubeconfig file into a temporary kubeconfig.yml file (this will be destroyed automatically after this step runs)
- echo $KUBECONFIG | base64 -d > kubeconfig.yml
# Tell our Kubernetes deployment to use the new Docker image tag
- kubectl --kubeconfig=kubeconfig.yml --namespace=<namespace> set image deployment/<deployment-name> <deployment-name>=<docker-username>/<docker-image>:$BITBUCKET_COMMIT
@dapseen
Copy link

dapseen commented Nov 4, 2019

Helpful

where are these params coming from <docker-username>/<docker-image>:

@dane-stevens
Copy link
Author

Those params come from either Account variables, Repository variables or Deployment variables that you can setup in Bitbucket. Here's an article on how to set those as well as default variables that are available: https://confluence.atlassian.com/bitbucket/variables-in-pipelines-794502608.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment