Bitbucket app passwords and the Bitbucket REST API allow you to deploy an artifact that has been produced by your pipeline, into the Bitbucket's Downloads area.

See also Test with databases in Bitbucket Pipelines.

Step 1: Create an App password for the repository owner

Log in to Bitbucket as the repository owner and go to Bitbucket Settings > App Passwords.

Create a new app password with write permissions to your repositories, and take note of the generated password that pops up. The name of the password is only for your reference, so use "Pipelines" or any other name you like.

Outcome

You should now have the app password to authenticate your pipe.

Step 2: Create a Pipelines variable with the authentication token

In order to upload files to Bitbucket Downloads you will need to configure the following variables:

Parameter

Value

BITBUCKET_USERNAMEBitbucket username of the repository owner (and also the user who will upload the artifacts)
BITBUCKET_APP_PASSWORDApp password as generated by bitbucket

You can define these variables for a specific deployment environment, in the repository settings, or in the settings for the account that owns the repository.

The example below shows the settings for an individual account variable, where the repository is owned by an individual. (Note that in the case where a team owns the repository, you must configure variables in the team settings for them to be visible in Pipelines.)

Outcome

You should now have these two variables configured in your repository and ready to be used from a pipeline.

Step 3a: Deploy your artifacts using the bitbucket-upload-file pipe

Use bitbucket-upload-file pipe to upload your artifact to Bitbucket Downloads. You just need to reference the file you want to upload from your build output. 

Below, there is a simple example from a Android project built with Gradle. You can make your debug Android Package (APK) available in Bitbucket Downloads.

bitbucket-pipelines.yml
image: maven:3.3.3

pipelines:
  default:
    - step:
        script:
          - pipe: atlassian/bitbucket-upload-file:0.1.2
            variables:
              BITBUCKET_USERNAME: $BITBUCKET_USERNAME
              BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
              FILENAME: "app/build/outputs/apk/debug/application-debug.apk"

Outcome

After that step you should have a bitbucket_pipeline.yml file with the pipe configuration. When the step completes, your artifact will be uploaded to the Downloads section in your repository.

Step 3b: Deploy your artifacts using curl and the Bitbucket REST API

With the variable and app password in place, you can now use curl in your build script to deploy artifacts to Bitbucket via the REST API:

curl -X POST "https://${BITBUCKET_USERNAME}:${BITBUCKET_APP_PASSWORD}@api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"app/build/outputs/apk/debug/application.apk"

Below, there is a simple example from a Android project built with Gradle. You can make your debug Android Package (APK) available in Bitbucket Downloads.

bitbucket-pipelines.yml
image: maven:3.3.3

pipelines:
  default:
    - step:
        script:
          - mvn -B clean install
          - curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"app/build/outputs/apk/debug/application.apk"

Outcome

After that step you should have a bitbucket_pipeline.yml file with the pipe configuration. When the step completes, your artifact will be uploaded to the Downloads section in your repository.


You can check your bitbucket-pipelines.yml file with our online validator.