Deploy build artifacts to Bitbucket Downloads

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.

Step 1: Create an App password for the repository owner

Log in to Bitbucket as the repository owner (also the user who will upload the files) 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.

You should now have two values that you will need for the next step.

Parameter Value
<username> Bitbucket username of the repository owner (and also the user who will upload the artifacts)
<password> App password as generated by bitbucket

Step 2: 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)

You can define this variable 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.)

Step 3: 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 Nov 26, 2018

Was this helpful?

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