Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Tagging a release with Bitbucket Pipelines


I am trying to write a Bitbucket Pipelines script that automatically add a git tags to on the master branch


image: maven:3.3.3

    - step:
          - mvn clean install
      - step:
            - mvn clean install
            - git tag THE_VERSION
            - git push


Pipelines gives me an error saying it is unable to authenticate to when it attempts the push

remote: Invalid username or password. If you log in via a third party service you must ensure you have an account password set in your account profile.
fatal: Authentication failed for 'https://x-token-auth:{access_token}'

Anyone have any ideas how I get this working?



3 answers

Mine script is below. To use it, you need to

  1. Add SSH keys in Repo -> Settings -> Pipelines -> SSH keys
  2. Public key add to Team or you Profile SSH keys
- step: &tag
name: Tag version
image: atlassian/default-image:2
- git remote set-url origin ${BITBUCKET_GIT_SSH_ORIGIN}

- dt=$(date '+%Y-%m-%d_%H%M');
- git tag $dt ${BITBUCKET_COMMIT}
- git push origin --tags

Here you have full documentation of pipeline-git authorization:

I was having a similar issue "fatal: could not read Username for '': No such device or address".

The Bitbucket docs linked above suggest that this should just work without having to switch to ssh.  On further investigation, it seems that I was getting the error because I was using my own Docker image in the step.  I refactored this bit of the pipeline into its own step and used one of the stock Bitbucket agents (in my case I added image: python:3.7.2). This then worked fine.

I know it's a tiny bit slower and won't suit all cases, but worked well for me and is a bit simpler than messing with SSH keys.

Part of my build process I also push back to the same repo.  Using an oauth token I run this command to set my remote with auth:

    git remote set-url origin https://x-token-auth:${BITBUCKET_TOKEN}${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}.git

The BITBUCKET_TOKEN env variable was something I generate in my scripts because they expire, so I need to generate a new one each build.

In my case, I also needed to setup the user config:

    git config --global ""

    git config --global "Build"


Then I could do whatever git operations I needed to do.

Thanks Alex

Are you able to share the script you use to generate  BITBUCKET_TOKEN? I am confused how you do this.


Like Mateusz Przybyłek likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,792 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you