how to get changed file path on event based webhook json payload ?
Asked by Madan Shah:

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.


Answers:
author: Mark C
body: Hi [@Madan Shah](/t5/user/viewprofilepage/user-id/4454569)

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](https://bitbucket.org/product/features/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.](https://bitbucket.org/blog/conditional-steps-and-improvements-to-logs-in-bitbucket-pipelines)  
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:

* [Get started with Bitbucket Pipelines](https://support.atlassian.com/bitbucket-cloud/docs/get-started-with-bitbucket-pipelines/)
* [Configure bitbucket-pipelines.yml](https://support.atlassian.com/bitbucket-cloud/docs/configure-bitbucket-pipelinesyml/)

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

Regards  
Mark C


Tags: bitbucket-cloud

cloud