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.

パラメーター
<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 environment variable with the authentication token

Define a new secure environment variable in your Pipelines settings:

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

You can define this environment variable either 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 environment variable, where the repository is owned by an individual. (Note that in the case where a team owns the repository, you must configure environment 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 environment 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}@api.bitbucket.org/2.0/repositories/${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.

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=@"target/output.jar"

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

最終更新日 2017 年 11 月 22 日

この翻訳に満足しましたか?

はい
いいえ
この記事についてのフィードバックを送信する

お探しの情報が見つかりませんか?

コミュニティへの質問

Powered by Confluence and Scroll Viewport.