Missed Team ’24? Catch up on announcements here.

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

How to trigger a pipeline on branch delete?

Deleted user March 20, 2023

I tried to search a lot but have not got proper answer.

In my case, I want to run a pipeline when a branch is deleted, basically it will help to remove the resources used for example k8s pods/deployments.

We create development environments whenever a branch is created so now to want to remove these environments once that branch is deleted.

Please do suggest a valid way to do so. Is there any add-on available?

1 answer

1 vote
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 21, 2023

Hello @[deleted] ,

Thank you for reaching out to Atlassian Community!

I'm afraid that it would not be possible to run a pipeline for a deleted branch, as the pipeline will look for the bitbucket-pipelines.yml file on that branch and since the branch is gone the file would no longer exist.

Since your goal is to do some cleanup in the environments that were used from previous pipelines, I would suggest using a custom pipeline. Custom pipelines are only manually triggered and you can select in the UI which branch or commit you want it to run. Also, it's possible to provide variables during the pipeline trigger of a custom pipeline, which allows you to have dynamic values in each run.

Following is an example of using a custom pipeline with variables : 

      - variables:
          - name: Username
          - name: Region
            default: ap-southeast-2  # optionally provide a default value
      - step:
            - echo "User name is $Username"
            - echo "and they are in $Region"

 In this example, the pipeline would expect the variables Username and Region to be provided. You will be prompted to provide those variables when running the pipeline manually from Pipelines page > Run Pipeline. For variables that have a default value, if no different value is provided, the default one will be used.

You can read more about custom pipelines in our Scheduled and manually triggered pipelines documentation.

Thank you, @[deleted] !

Patrik S

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events