Ludo
Ludo

Reputation: 2527

Push to private bitbucket repo from pipelines

I am trying to commit and push to a bitbucket repo from bitbucket pipelines. However, it's a private repo so what is the easiest way to gain access to it?

This is what my script looks like:

pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - VERSION=$(<version.txt)
          - echo $VERSION 0.1 | awk '{print $1 + $2}' > version.txt
          - echo $(<version.txt)
          - git config --global push.default simple
          - git remote set-url origin https://[email protected]/company/repo.git
          - git config user.name "myname"
          - git config user.email "[email protected]"
          - git add version.txt
          - git commit -m "[skip CI]"
          - git push
          - echo "New version = $VERSION"

It gets stuck at the push command and returns:

fatal: could not read Password for 'https://[email protected]': No such device or address

How do I set my password for it or is there a way to do it without password? For it to somehow realise that it's already within the repo itself. I read around about SSH keys but am not very familiar with the concept and how to use them.

Upvotes: 1

Views: 2269

Answers (1)

Jim Redmond
Jim Redmond

Reputation: 5640

Use a secure environment variable named something like BB_AUTH_STRING, and give it a value of username:password. (It's safest to do this with an app password, since those will only work with the scope you give them.) That will also change your remote URL to https://${BB_AUTH_STRING}@bitbucket.org/owner/repo.git.

Upvotes: 3

Related Questions