Last active
November 4, 2019 11:00
-
-
Save dane-stevens/054d3d54ee97d36856429ccdcfdb5e0b to your computer and use it in GitHub Desktop.
Sample Bitbucket Pipelines Config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
Helpful
where are these params coming from
<docker-username>/<docker-image>: