The pipe bitbucket-pipe-release:5.0.1 fails to commit changes to the main branch
Asked by Christof Koegler _Gaims GmbH_:

I am using the Bitbucket pipe bitbucket-pipe-release:5.0.1 to push a custom pipe to our managed repository. Both pushing and pulling succeeds, and the custom pipe works fine.

Recently, I added a step to my pipeline which will, in addition to releasing the custom pipe, create a tag, update the version, and commit all changes to the master branch, as per bitbucket-pipe-release's [documentation.](https://bitbucket.org/product/features/pipelines/integrations??&search=release&p=atlassian/bitbucket-pipe-release) This branch only triggers whenever the committed .env file changes. When I run the step, however, it fails to push the changes to the main branch:

![Screenshot from 2022-09-26 13-36-49.png](https://community.atlassian.com/t5/image/serverpage/image-id/217747iA27470C2CAD66FFB/image-size/large?v=v2&px=999 "Screenshot from 2022-09-26 13-36-49.png")

Here is the step definition:  

```
push: &push
  step:
  name: Push and tag new version
  runs-on:
  - gaims
  image: python:3.10
  script:
  - APP_VERSION=$(cat .env | grep -oP "APP_VERSION=[/']?\K[\d/.]*")
  - pipe: docker://bitbucketpipelines/bitbucket-pipe-release:5.0.1
    variables:
      REGISTRY_USERNAME: $REGISTRY_USER
      REGISTRY_PASSWORD: $REGISTRY_PWD
      IMAGE: $REGISTRY_URL/bitbucket/$BITBUCKET_REPO_SLUG
      REGISTRY_URL: $REGISTRY_URL
      VERSION: $APP_VERSION
      BITBUCKET_BRANCH: main
      CHANGELOG: 'false'
  condition:
    changesets:
      includePaths:
        - ".env"
  services:
  - docker

pipelines:
  default:
  - <<: *test
  - <<: *push-dev
  branches:
    develop:
    - <<: *test
    - <<: *push
    main:
```

The main branch is indeed called 'main' and I have not restricted read/write access to it. Why does the pipeline fail?


Answers:
author: Igor Stoyanov
body: Hi [@Christof Koegler _Gaims GmbH_](/t5/user/viewprofilepage/user-id/5011301) .Thanks for your question.

Try manually run all git commands firstly on local machine to see if any errors, then on pipeline without using pipe to see if any errors and notify us with the result.  

Regards, Igor.

comments: author: Christof Koegler _Gaims GmbH_
body: Hi [@Igor Stoyanov](/t5/user/viewprofilepage/user-id/4550492) . Thanks for getting back to me.

I do not exactly know how this is implemented in the pipe, so it is hard to reproduce locally. However, I have adjusted the step to merge the changes made by the pipe (updating the version in README.md and pipe.yml) into the main branch 'manually' after the pipe has run:

```
push: &push
  step:
    name: Push and tag new version
    runs-on:
    - gaims
    image: python:3.10
    clone:
      depth: full
    script:
    - APP_VERSION=$(cat .env | grep -oP "APP_VERSION=[/']?\K[\d/.]*")
    - pipe: docker://bitbucketpipelines/bitbucket-pipe-release:5.0.1
      variables:
        REGISTRY_USERNAME: $REGISTRY_USER
        REGISTRY_PASSWORD: $REGISTRY_PWD
        IMAGE: $REGISTRY_URL/bitbucket/$BITBUCKET_REPO_SLUG
        REGISTRY_URL: $REGISTRY_URL
        VERSION: $APP_VERSION
        CHANGELOG: 'false'
    - git pull
    - git checkout main
    - git merge --no-ff -m "Merge version $APP_VERSION into main branch [skip ci]" $BITBUCKET_BRANCH
    - git push
    condition:
      changesets:
        includePaths:
          - ".env"
    services:
    - docker
```

This works and achieves the desired end result. However, it was my understanding that the pipe provides that functionality as well. From the pipe docs:

![Screenshot from 2022-10-04 13-09-41.png](https://community.atlassian.com/t5/image/serverpage/image-id/219076i17CFB0B1C7C2554D/image-size/large?v=v2&px=999 "Screenshot from 2022-10-04 13-09-41.png")

I understood this to mean that the pipe will push the changes made to the branch specified under BITBUCKET_BRANCH. Or am I misreading this?

Thanks

Chris


author: Igor Stoyanov
body: Your error was here:

```
git push -u origin main
```

Usually this means you don't have main branch. To ensure that main branch exists i suggested you to manually push to main branch.

Also all git commands presented on your provided screenshot.

I can't see any problems with your yml configuration, all should work.

And yes, if you want to release into main branch, you should provide this

```
BITBUCKET_BRANCH: main
```

into variables.


author: Igor Stoyanov
body: Okey, i finally reproduced your issue. I will investigate it and notify you later


author: Christof Koegler _Gaims GmbH_
body: Great, thanks.


author: Oleksandr Kyrdan
body: Hi [@Christof Koegler _Gaims GmbH_](/t5/user/viewprofilepage/user-id/5011301)

We have investigated the issue and found that it could happened when you have a setup with parameters for a branch different than build based on the branch build runs. Documentation is updated accordingly.

So, we don't recommend to provide a BITBUCKET_BRANCH variable for the pipe. It will be available by default in the build and in the setup during git clone.

Best regards,  
Oleksandr Kyrdan


author: Christof Koegler _Gaims GmbH_
body: Thanks [@Oleksandr Kyrdan](/t5/user/viewprofilepage/user-id/2885705) for investigating and updating the documentation accordingly.

I will stick to pushing the files into the main branch 'manually' as described in my previous answer.  

Best regards  
Chris


Tags: bitbucket-cloud

cloud