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

pipeline branch to another branch in the same repository

Ivo
Contributor
June 19, 2024

Hi guys, I have 1 repository with 2 branches and I need to push the changes from branch-1 to branch-2. I know this is possible to be done with the anchors but I'm not sure exactly how. 

Below is my simple pipeline example

steps:
      steps:
      - step: &build
          name: Build and run Composer
trigger: automatic deployment: BRANCH-1 runs-on: - 'self.hosted' - 'linux.arm64' - 'customlabel' script: - apt update - apt install -y list-of-packages - docker-php-ext-enable list-of-extensions - docker-php-ext-install list-of-extentions - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer - composer install - ./vendor/bin/phpstan - ./vendor/bin/phpunit - apt-get clean - rm -rf /var/lib/apt/lists/* /tmp/pear caches: - composer artifacts: - '**' - step: &deploy name: Deploy to development deployment: DEVOPS-1 runs-on: - 'self.hosted' - 'linux.arm64' - 'customlabel' script: - echo $BITBUCKET_BRANCH pipelines: pull-request: 'BRANCH-1': - step: *build - step: *deploy 'BRANCH-2': - step: *build - step: *deploy branches: BRANCH-2: - step: *build - step: <<: *deploy deployment: BRANCH-1 BRANCH-1: - step: *build - step: <<: *deploy deployment: BRANCH-1

 

Regards,

 

2 answers

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 21, 2024

Hi @Ivo,

I'm a bit confused by what you are trying to achieve, mainly because you mention anchors in your post. YAML anchors allow you to reuse steps in your bitbucket-pipelines.yml file in order to avoid repeated sections. For example, if you want the exact same step to be executed on pushes to branch-1 and branch-2, you can use an anchor (you are already doing that in the yml file you shared).

You mention in your post, though, that you want to push changes from branch-1 to branch-2. Can you please clarify whether you're trying to do the following: whenever there are new commits in branch-1, run a pipeline that will push these commits to the Bitbucket repo, to branch-2? Is this what you want to do? If not, can you please explain further?

Kind regards,
Theodora

Ivo
Contributor
June 21, 2024

Hi @Theodora Boudale ,

The idea is all new successful pull requests to be pushed to development branch. For example we have BRANCH-* on success to be pushed on development branch, because after the tests they don't have any errors. For now I want to test this in Bitbucket (branch-1 -> branch-2 in the same repository) but when this work fine I would like the change the pipeline to push these changes to remote server where the application is. 

Regards,

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 24, 2024

Hi @Ivo,

Thank you for the info.

This is a sample step you can use in the pipeline of BRANCH-1:

- step:
clone:
depth: full
script:
- git checkout BRANCH-2
- git merge BRANCH-1 -m "merged branch-1 into branch-2 [skip ci]"
- git push

In this step, I am defining that the depth of the clone should be full, so that I can check out additional branches.

In the script for this step, I am checking out BRANCH-2. Then, I merge BRANCH-1 into BRANCH-2. I provide a message for the merge commit and I include [skip ci] so that the push won't trigger the pipeline for BRAANCH-2. If you want it to be triggered, simply omit the [skip ci] from the commit message. Finally, the merge commit will be pushed to BRANCH-2 with the git push command.

Git should be installed in the Docker image you use as a build container for this step, so it can run these Git commands. If it is not already installed, you will need to add a command in the script that installs Git.

It's also important to note that if there are conflicts during the merge, then the git merge command and the pipeline will fail.

Kind regards,
Theodora

Ivo
Contributor
June 24, 2024

Hi @Theodora Boudale ,

Thank you.

I will test with git to push the changes to the branch and then upload them to the remote server later. 

Regards,

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 25, 2024

You are very welcome, Ivo!

Just to clarify, the sample pipeline step I shared will merge BRANCH-1 into BRANCH-2, and then push the changes to the Bitbucket Cloud repo.

Additional configuration will be required if you want to push to a remote server, that depends also on what tool you want to use to deploy the changes.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events