Deploy with Bitbucket Pipelines
Mia-Platform Console can be configured to deploy your Project using Bitbucket Pipelines.
To deploy your projects using Bitbucket Pipelines, you must add the Bitbucket Cloud Provider in the Company Overview page, selecting the CI/CD Tool option, and then follow the standard Provider configuration.
This process will change the configuration of your Company. In particular, the JSON configuration of the field Pipelines will change as follows:
{
"type": "bitbucket-pipelines",
"providerId": "{{PROVIDER_ID}}"
}
Where PROVIDER_ID will be equal to the ID of the Bitbucket Cloud CI/CD Tool Provider that has been set up previously.
If you haven't set up a Bitbucket Cloud provider yet, check out here how to configure it. Make sure that the token configured for your provider has the Pipelines read and write permissions enabled.
If you haven't set up an environment yet, check out here how to configure it.
Workflow
When a user triggers a Deploy from the Console, the following steps are executed:
- The Console sends an API request to Bitbucket Cloud to trigger a custom pipeline on the configured repository;
- Bitbucket Pipelines runs the pipeline steps defined in the
bitbucket-pipelines.ymlfile; - When the pipeline status of deployments changes, the Console updates to show you its current status.
Pipeline Configuration
In your Bitbucket Cloud Configurations' repository, create a bitbucket-pipelines.yml file at the root of the repository. Below is a basic example to get started:
image: atlassian/default-image:4
pipelines:
custom:
"<ENVIRONMENT_TO_DEPLOY>":
- step:
name: "Deploy to $ENVIRONMENT_TO_DEPLOY"
deployment: "$ENVIRONMENT_TO_DEPLOY"
script:
- apt-get update && apt-get install -y curl
# Add your deployment logic here, for example using mlp:
# - curl -sL https://github.com/mia-platform/mlp/releases/latest/download/mlp-linux-amd64 -o mlp
# - chmod +x mlp
# - ./mlp deploy --environment $ENVIRONMENT_TO_DEPLOY --revision $REVISION
- echo "Deploying revision $REVISION to $ENVIRONMENT_TO_DEPLOY"
For pipeline-based deployments it is possible to leverage mlp, Mia-Platform's command line tool responsible for creating, updating and deleting Kubernetes resources based on the files generated by the Console.
Repository Variables
To securely store credentials and configuration values needed by the pipeline (such as Kubernetes cluster credentials), it is possible to use inherited Bitbucket Repository Variables. These variables can be set in the Repository settings > Pipelines > Repository variables section of your Bitbucket Cloud repository. The inherited approach is not mandatory and you can use other environments and secrets providers like (Azure Key Vault, Hashicorp Vault and other solutions).
Deployment Tracking
Bitbucket Pipelines supports Deployments to track deployment history across different environments. By setting the deployment field in a pipeline step, Bitbucket will record each deployment and make it visible in the Deployments tab of your repository.
Make sure the environment names in bitbucket-pipelines.yml match the environment IDs configured in the Mia-Platform Console.