Deploy build artifacts to Bitbucket Downloads

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

Deploying the artifacts or output produced by your Bitbucket Pipelines build to Bitbucket's Downloads area is simple with Bitbucket app passwords and the Bitbucket REST API.

See also Test with databases in Bitbucket Pipelines.

Create an App password for the repository owner

  1. Log in to Bitbucket as the repository owner (also the user who will upload the files).
  2. In Bitbucket go to your profile > Bitbucket Settings > App Passwords.
  3. 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.

    You should now have two values that you will need for the next step.
<username>Bitbucket username of the repository owner, and the user who will upload the artifacts.
<password>App password as generated by bitbucket

Create a Pipelines variable with the authentication token

Define a new secure variable in your Pipelines settings:

  • Parameter name: BB_AUTH_STRING
  • Parameter value: <username>:<password> (using the values from step 1)

To define these variables for a specific deployment environment go to your repository > Settings, and under Pipelines click Account variables.

The following example shows the settings for an individual account variable, where the repository is owned by an individual.

Note that if a team owns the repository, you must configure variables in the team settings for the team mates to be able to see them in Pipelines.

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://${BB_AUTH_STRING}${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"target/output.jar"

Below is a simple example from a Java project built with Maven. You should update the "target/output.jar" file name and other details to match your project. If you'd like to get really fancy, you could use default variables like BITBUCKET_BUILD_NUMBER to create a unique file name each time.

image: maven:3.3.3

    - step:
          - mvn -B clean install
          - curl -X POST --user "${BB_AUTH_STRING}" "${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"target/output.jar"

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

Last modified on Aug 19, 2019

Was this helpful?

Provide feedback about this article
Powered by Confluence and Scroll Viewport.