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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

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

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

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.

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

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.

Suggest an answer

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

Calling any interview participants for Bitbucket Data Center

Hi everyone,  We are looking to learn more about development teams’ workflows and pain points, especially around DevOps, integrations, administration, scale, security, and the related challeng...

442 views 4 4
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