Missed Team ’24? Catch up on announcements here.

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

Tagging a release with Bitbucket Pipelines

Richard Hensman
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 17, 2016

Hi 

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

pipelines:
  default:
    - step:
        script:
          - mvn clean install
  branches:
    master:
      - step:
          script:
            - 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}@bitbucket.org/deepskyblue/xero-client.git/'

Anyone have any ideas how I get this working?

thanks

Richard

3 answers

2 votes
Mateusz Przybyłek March 18, 2020

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
script:
- 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: https://confluence.atlassian.com/bitbucket/push-back-to-your-repository-962352710.html

0 votes
John Carpenter
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 16, 2020

I was having a similar issue "fatal: could not read Username for 'http://bitbucket.org': 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.

0 votes
Alex Soto August 17, 2016

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.org/${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 user.email "builder@example.com"

    git config --global user.name "Build"

 

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

Richard Hensman
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 26, 2016

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
TAGS
AUG Leaders

Atlassian Community Events