|
| 1 | +--- |
| 2 | +Order: 35 |
| 3 | +Title: BitBucket Pipelines |
| 4 | +Description: Details on the Atlassian BitBucket Pipelines support in GitVersion |
| 5 | +RedirectFrom: docs/build-server-support/build-server/bitbucket-pipelines |
| 6 | +--- |
| 7 | + |
| 8 | +## Basic Usage |
| 9 | + |
| 10 | +To use GitVersion with Atlassian BitBucket Pipelines, you will need to install and run the GitVersion CLI tool |
| 11 | +in your build step. |
| 12 | + |
| 13 | +## Executing GitVersion |
| 14 | + |
| 15 | +### Using the GitVersion CLI tool |
| 16 | + |
| 17 | +An example pipeline is shown below: |
| 18 | + |
| 19 | +```yml |
| 20 | +image: mcr.microsoft.com/dotnet/sdk:6.0 |
| 21 | + |
| 22 | +clone: |
| 23 | + depth: full |
| 24 | + |
| 25 | +pipelines: |
| 26 | + default: |
| 27 | + - step: |
| 28 | + name: Version and build |
| 29 | + script: |
| 30 | + - export PATH="$PATH:/root/.dotnet/tools" |
| 31 | + - dotnet tool install --global GitVersion.Tool --version 5.* |
| 32 | + - dotnet-gitversion /buildserver |
| 33 | + - source gitversion.env |
| 34 | + - echo Building with semver $GITVERSION_FULLSEMVER |
| 35 | + - dotnet build |
| 36 | +``` |
| 37 | +
|
| 38 | +:::{.alert .alert-danger} |
| 39 | +**Important** |
| 40 | +
|
| 41 | +You must set the `clone:depth` setting as shown above; without it, BitBucket Pipelines will perform a shallow clone, which will |
| 42 | +cause GitVersion will display an error message. |
| 43 | +::: |
| 44 | + |
| 45 | +When the action `dotnet-gitversion /buildserver` is executed, it will detect that it is running in BitBucket Pipelines by the presence of |
| 46 | +the `BITBUCKET_WORKSPACE` environment variable, which is set by the BitBucket Pipelines engine. It will generate a text file named `gitversion.env` |
| 47 | +which contains all the output of the GitVersion tool, exported as individual environment variables prefixed with `GITVERSION_`. |
| 48 | +These environment variables can then be imported back into the build step using the `source gitversion.env` action. |
| 49 | + |
| 50 | +If you want to share the text file across multiple build steps, then you will need to save it as an artifact. A more complex example pipeline |
| 51 | +is shown below: |
| 52 | + |
| 53 | +```yml |
| 54 | +image: mcr.microsoft.com/dotnet/sdk:6.0 |
| 55 | +
|
| 56 | +clone: |
| 57 | + depth: full |
| 58 | +
|
| 59 | +pipelines: |
| 60 | + default: |
| 61 | + - step: |
| 62 | + name: Version |
| 63 | + script: |
| 64 | + - export PATH="$PATH:/root/.dotnet/tools" |
| 65 | + - dotnet tool install --global GitVersion.Tool --version 5.* |
| 66 | + - dotnet-gitversion /buildserver |
| 67 | + artifacts: |
| 68 | + - gitversion.env |
| 69 | + - step: |
| 70 | + name: Build |
| 71 | + script: |
| 72 | + - source gitversion.env |
| 73 | + - echo Building with semver $GITVERSION_FULLSEMVER |
| 74 | + - dotnet build |
| 75 | +``` |
| 76 | + |
| 77 | +[Variables and Secrets](https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/) |
| 78 | +[Clone Options](https://bitbucket.org/blog/support-for-more-clone-options-at-the-step-level) |
0 commit comments