How to push LFS files using Bitbucket Pipelines?

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

This article focuses on the process of pushing LFS files to a Bitbucket repository from Bitbucket Pipelines.

Diagnosis

If you encounter an error while attempting to push an LFS file from a Bitbucket Pipeline, consider the following sample YAML configuration:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 image: atlassian/default-image:4 clone: lfs: true pipelines: default: - step: name: Push LFS file from Bitbucket Pipeline script: - echo "Hello World" >> Hello.json - apt-get update - apt-get upgrade -y - apt-get install -y git-lfs - git add . && git commit -m "[skip ci] LFS Push" - git push

In the above configuration, we are doing the following -

  • Creating a JSON file

  • Installing LFS

  • Pushing the JSON file in Bitbucket repository as an LFS object

We assume that json files are marked as LFS in .gitattributes.

However, the above configuration will fail with the following error -

1 2 3 4 5 6 7 8 9 10 11 12 git push fatal: could not read Username for 'https://bitbucket.org': No such device or address fatal: could not read Username for 'https://bitbucket.org': No such device or address fatal: could not read Username for 'https://bitbucket.org': No such device or address Git credentials for https://bitbucket.org/%7B%7D/%7B<repo_UUID>%7D/info/lfs/object/verify?upload_id=<upload-ID> not found. error: failed to push some refs to 'http://bitbucket.org/<workspace-ID>/<repo-slug>'

Cause

The reason for the failure is that the default authentication method does not allow the LFS push. You will also notice that the workspace ID is not filled in the URL in the error message -

https://bitbucket.org/%7B%7D/%7B%7D/%7B<repo_UUID>%7D/info/lfs/object/verify?upload_id= which when decoded translates to -

https://bitbucket.org/{}/{repo-UUID}/info/lfs/object/verify?upload_id=<ID>

You can find more details about this issue from BCLOUD-23180.

Solution

To resolve this issue, consider using an alternative authentication method. Two viable options are outlined below:

  • Utilize HTTPS Username and App Password for authentication. Modify your git push command as follows:

    1 git push https://$username:$app_password@bitbucket.org/<workspace-id>/<repo-ID>.git

    This approach leverages specific username and app password values that can be provided through variables.

  • SSH-based authentication also serves as a valid solution. Adjust your repository's remote URL to point towards the SSH URL with this command:

    1 git remote set-url origin "$BITBUCKET_GIT_SSH_ORIGIN"

Updated on February 25, 2025

Still need help?

The Atlassian Community is here for you.