Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

how to get changed file path on event based webhook json payload ?

Madan Shah
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 27, 2021

I am trying to create a AWS codepipeline which will be trigger when certain files are uploaded on specific folders on the MonoRepo. for eg: I have a monorepo with my frontend in Folder_A (reponame/apps/folder_A)and Backend on Folder_B(reponame/apps/folder_B). If I make changes to a file inside Folder_A and push, AWS codepipeline (Codepipeline for Folder_A)  should be triggered.

This is how I planned to implement the solution. Whenever there is a PR, the webhook payload is sent to AWS API Gateway  which then triggers lambda and pushes payload to lambda. The code in lambda will identify the path of the file changed and triggers respective AWS code pipeline. But I am unable to get the information on which folder was updates on the  webhook payload i.e path of the file changed on bitbucket. I am looking for a way to get the filepath on webhook payload.

1 answer

0 votes
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 1, 2021

Hi @Madan Shah

Welcome to the community.

I'm afraid Bitbucket Cloud Webhooks does not include file paths as payloads while triggering an event (e.g. push, pull request updates).
You can check this link for more information about Bitbucket Cloud Webhooks' available payloads. - https://support.atlassian.com/bitbucket-cloud/docs/manage-webhooks/ (See "Trigger webhooks" section)

As a workaround, I believe your use-case is doable by using Bitbucket Pipelines.
Bitbucket Pipelines is a CI/CD tool within your repository where you can run scripts/commands to build, test, and deploy your code.

Based on your use case, assuming your mono-repositories are located in a single repository on Bitbucket Cloud:

  • apps/folder_A
  • apps/folder_B

You can set up a Pipelines YAML configuration that triggers by default and by using Conditional Steps.
Using Conditional steps, you can execute a step only if one of the modified files matches the expression in includePaths.

Here's a sample YAML file where you can use the default Pipelines trigger and Conditional steps:

pipelines:
  default:
    - step:
          name: "Monorepo 1"
          condition:
              changesets:
                  includePaths:
                    - "apps/folder_A/**"
          script:
            - echo "Execute commands here (e.g. running a CodePipeline script/command)"
    - step:
          name: "Monorepo 2"
          condition:
              changesets:
                  includePaths:
                    - "apps/folder_B/**"
          script:
            - echo "Execute commands here (e.g. running a CodePipeline script/command)"

The above YAML configuration will trigger a Pipelines build each time you push a commit in the branch where you pushed the YAML configuration (initially, it will be your main branch).
However, a step will be paused if the file changes made or pushed are not within the specified path (or includePaths).

Here are some links that will help you get started with Bitbucket Pipelines:

You can give it a try and let me know how it goes.

Regards
Mark C

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events