Stopping pipeline from running when a new branch is created
Asked by Sena Turku Cakmak:

Hey,

1) I realised that everytime someone creates a new branch from the main branch, it automatically triggers the pipeline even though nothing was changed in the repository. It gets the commit message from the last commit and reruns the entire process in the created branch. I do not want the pipeline to be triggered unless I push my changes. I don't want the pipeline to run with every new branch. How can I do it?

2) There is an *Other* (custom name) section in bitbucket while creating the branch, how can I add that branches that falls under "*Other*" to the yml file to run certain steps?

Thanks in advance!


Answers:
author: Ben
body: Hi [@Sena Turku Cakmak](/t5/user/viewprofilepage/user-id/5436154)

1) If you have a **default**section configured in your YML configuration - this will trigger a build every single time a push is made to the repository.

The creation of a new branch involves pushing that new branch to the repository, hence why the build is triggered - for example this step would run on every single repository push (including when you create a new branch):  

```
pipelines:
    default:
     - step:
        name: Test
        script:
             - echo "Hello world!"
```

Therefore if you didn't want builds to run whenever you create a new branch, you'll need to remove the default section.

2) Any time you wish to trigger steps when a particular branch is pushed to, you would use the **branches** tag and specify its relevant branch name - for example this step would only run whenever the **test**branch is pushed to:

```
pipelines:
    branches:
        test:
         - step:
           name: Hello world
           script:
                - echo "Hello world!"
```

You can find more information regarding YML configuration below:

* <https://support.atlassian.com/bitbucket-cloud/docs/bitbucket-pipelines-configuration-reference/>

Hope this helps.

Cheers!

- Ben (Bitbucket Cloud Support)

comments: author: Sena Turku Cakmak
body: Thanks for the answer, but I have some questions.

1) We do not have a default section configured in the pipeline, but it is triggering the build when we create a new branch anyway. The code is looking like this:

```
definitions:
    steps:
     - step: &Test
         name: 'Step 1'
         script:
          - echo "Hello world!"


pipelines:
    branches:
        master:
         - step: Test*
           
        feature/*:
         - step: Test*
```

is there another way to fix this, or I might be missing someting?

2) We create branches with various names depending on the task, so it is not possible to define all the branch names in the .yml file. Is there a generalized way to address those *Other* branches in .yml file? I know "default" option might do the job, but if "default" in some way affects triggering the build when a branch is created as you mentioned in question 1, I do not want to trigger the build so I cannot use that.

Thanks for your help in advance!


author: Ben
body: Hi Senal,

May I know what the name of the branch is that you are creating when branching from master?

Default is the catch all for any branches that are not defined in the YML configuration, you can use wildcards to target branches starting with a particular word (as you have done with feature), but unfortunately aside from this each must be defined.

Cheers!

- Ben (Bitbucket Cloud Support)


author: Sena Turku Cakmak
body: *"May I know what the name of the branch is that you are creating when branching from master? "*

It depends on what the problem is, it changes all the time, whatever the user decides :) But I think we are going to use the default option like you mentioned, thanks for the answer!

**About my first question, is there any solution?**

*1) We do not have a default section configured in the pipeline, but it is triggering the build when we create a new branch anyway. The code is looking like this:*

```
definitions:
    steps:
     - step: &Test
         name: 'Step 1'
         script:
          - echo "Hello world!"


pipelines:
    branches:
        master:
         - step: Test*
           
        feature/*:
         - step: Test*
```

Here is an example of a situation that I encountered even though I didn't have a "default" pipeline configuration:

![2024-05-06 12_41_01-.png](https://community.atlassian.com/t5/image/serverpage/image-id/322066i9E6E71778135C5B8/image-size/large?v=v2&px=999 "2024-05-06 12_41_01-.png")

As you can see here, a branch called "bait" is created by me, and the pipeline is automatically triggered for #525 , with the same commit message and he same commit number from the last commit that I pushed before, #524 which is totally unrelated to #525. The only difference between them is the branch. I want to prevent #525 from happening. Is there a way for it?


author: Ben
body: Hi Sena,

I've just noticed that you have access to a Premium workspace, so you are entitled to 1:1 Premium support directly from our support team.

I will need to gain access to your workspace to check your YML, build logs are other configurations - to do so our system requires a formal support ticket. I've just raised one on your behalf, please check your email for further correspondence.

Cheers!

- Ben (Bitbucket Cloud Support)


Tags: bitbucket-cloud

cloud