Upload artifacts generated from a pipelines build to another repository
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Summary
This article explains how to upload a file to the downloads section of another repository using pipelines. This use case is helpful in situations where a user wishes to upload a file generated during the build process on Bitbucket pipelines to another repository.
Solution
There are API endpoints which may be used to upload files to the downloads section of another repository and also to fetch files from the other repositories download section.
Sample Script - Repository 1
image: atlassian/default-image:2
pipelines:
default:
- step:
name: Build and Test
script:
- mkdir test_folder
- cd test_folder
- echo "choose the password" > testfile.txt
- cat tetsfile.txt
- curl -u username:app_password -X POST 'https://api.bitbucket.org/2.0/repositories/workspace_name/repo_name/downloads' -F files=@testfile.txt
artifacts:
- test_folder/testfile.txt
The above piece of code uploads testfile.txt to the download section of another repository example: repo2.
Sample Script - Repository 2
On repo2 you may use a configuration similar to the one shown below to fetch the file from the download section of repo1:
image: atlassian/default-image:2
pipelines:
default:
- step:
- curl -O -L -u username:app_password https://api.bitbucket.org/2.0/repositories/workspace_name/repo_name/downloads/testfile.txt
This can also be performed using the bitbucket-upload-file pipe as described below. For more information on how to use this pipe, please refer to its documentation page.
script:
- pipe: atlassian/bitbucket-upload-file:0.3.4
variables:
BITBUCKET_USERNAME: $BITBUCKET_USERNAME
BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
FILENAME: 'package.json'
ACCOUNT: 'team-account'
REPOSITORY: 'awesome-repository-name'
If the above instructions do not assist with performing the uploading/fetching of artifacts within downloads, please raise a support ticket or raise a community support ticket for further assistance with this.