Bitbucket Cloud auto-versioning post-processing
You can delegate the post-processing to a Bitbucket pipeline.
Yontrack triggers a custom: pipeline with the variables describing the upgrade, reports
the link to the pipeline run in the auto-versioning audit, and waits for the pipeline to complete. The
post-processing fails when the pipeline does not complete successfully, or does not complete in time.
Note
The Bitbucket Cloud configuration used to trigger the pipeline needs a token with the pipelines write scope. See the Bitbucket Cloud configuration.
Settings
There is a global configuration, and there is a specific configuration at the branch level (in the
postProcessingConfig parameter).
For the global configuration, you can go to Settings > Bitbucket Cloud Auto Versioning Post Processing and define the following attributes:
- Configuration - Default Bitbucket Cloud configuration to use for the connection
- Workspace - Default workspace of the repository containing the pipeline
- Repository - Default repository containing the pipeline
- Pipeline - Name of the custom pipeline containing the post-processing (like
yontrack-auto-versioning) - Branch - Branch to run the pipeline on,
mainby default - Retries - The amount of times we check for the completion of the post-processing pipeline, 10 by default
- Retry interval - The time (in seconds) between two checks for the completion of the post-processing pipeline, 30 by default and never less than 10 seconds
Yontrack waits at most Retries x Retry interval for the pipeline to complete: 5 minutes by default.
The settings can also be set as code:
ontrack:
config:
settings:
bitbucket-cloud-av-post-processing:
config: bitbucket-cloud
workspace: my-workspace
repository: post-processing
pipeline: yontrack-auto-versioning
branch: main
retries: 10
retriesDelaySeconds: 30
Branch configuration
The postProcessingConfig property at the branch level accepts the following
parameters:
| Parameter | Default value | Description |
|---|---|---|
dockerImage |
Empty | This image defines the environment for the upgrade command to run in |
dockerCommand |
Empty | Command to run in the Docker container |
commitMessage |
Empty | Commit message to use to commit and push the result of the post-processing |
config |
Settings | Bitbucket Cloud configuration to use for the connection |
workspace |
Settings | Workspace of the repository containing the pipeline |
repository |
Settings | Repository containing the pipeline |
pipeline |
Settings | Name of the custom pipeline to run |
branch |
Settings | Branch to run the pipeline on |
The config, workspace, repository and pipeline must be defined, either at the branch level or in the settings,
otherwise the post-processing fails before any pipeline is triggered.
The dockerImage, dockerCommand and commitMessage parameters, and the branch, are
templated using the
auto-versioning templating context. For example:
commitMessage: "Upgrading to ${VERSION}"
Example of a simple configuration relying on the global settings:
postProcessing: bitbucket-cloud
postProcessingConfig:
dockerImage: eclipse-temurin:21
dockerCommand: ./gradlew dependencies --write-locks
commitMessage: "Resolving the dependency locks"
Example of a configuration running a pipeline defined in the target repository itself:
postProcessing: bitbucket-cloud
postProcessingConfig:
dockerImage: eclipse-temurin:21
dockerCommand: ./gradlew dependencies --write-locks
commitMessage: "Resolving the dependency locks"
workspace: my-workspace
repository: my-repository
pipeline: yontrack-auto-versioning
Pipeline variables
Yontrack triggers the pipeline with the following variables:
| Variable | Description |
|---|---|
REPOSITORY |
URI of the repository to process |
UPGRADE_BRANCH |
Branch containing the changes to process |
DOCKER_IMAGE |
This image defines the environment for the upgrade command to run in |
DOCKER_COMMAND |
Command to run in the Docker container |
COMMIT_MESSAGE |
Commit message to use to commit and push the result of the post-processing |
VERSION |
The version which is upgraded to |
The code below shows an example of a bitbucket-pipelines.yml custom pipeline suitable for post-processing:
pipelines:
custom:
yontrack-auto-versioning:
- variables:
- name: REPOSITORY
- name: UPGRADE_BRANCH
- name: DOCKER_IMAGE
- name: DOCKER_COMMAND
- name: COMMIT_MESSAGE
- name: VERSION
- step:
name: Post-processing
services:
- docker
script:
# Credentials able to push to the repository to process, as secured repository variables
- git clone --branch "${UPGRADE_BRANCH}" "https://x-token-auth:${PUSH_TOKEN}@${REPOSITORY#https://}" work
- cd work
- docker run --rm -v "$PWD:/work" -w /work "${DOCKER_IMAGE}" sh -c "${DOCKER_COMMAND}"
- git config user.name "Yontrack post-processing"
- git config user.email "yontrack@example.com"
- git add --all
- git commit -m "${COMMIT_MESSAGE} [skip ci]"
- git push origin "HEAD:${UPGRADE_BRANCH}"
Important
- all the variables Yontrack sends must be declared in the custom pipeline
- committing and pushing the changed files to
UPGRADE_BRANCHis required for the post-processing to be considered complete [skip ci]in the commit message prevents the push from starting the other pipelines of the repository
The rest of the pipeline can be adapted at will.