# Condition by file extension in commit possible?

**URL:** https://drone.discourse.group/t/condition-by-file-extension-in-commit-possible/12871
**Category:** Drone Support
**Created:** [November 20, 2022, 11:21am UTC](https://drone.discourse.group/t/condition-by-file-extension-in-commit-possible/12871 "2022-11-20T11:21:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kimpenhaus](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/kimpenhaus/32/5665_2.png) [@kimpenhaus](https://drone.discourse.group/u/kimpenhaus)
#### Post date: [November 20, 2022, 11:21am UTC](https://drone.discourse.group/t/condition-by-file-extension-in-commit-possible/12871/1 "2022-11-20T11:21:08Z")

</div>

Hi community,

this might be a stupid idea in general but I have a git repo containing vcf and ics files. I would like to trigger a build every time there are changes on any vcf file or new vcf files are added.

Is there any chance to glance into the commit and have a condition of that commit containing a vcf file?

Thanks for your help,  
Marcus

---

<div class="post-metadata">

### Author: ![d1wilko](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/d1wilko/32/6474_2.png) [@d1wilko](https://drone.discourse.group/u/d1wilko)
#### Post date: [November 21, 2022, 11:13am UTC](https://drone.discourse.group/t/condition-by-file-extension-in-commit-possible/12871/2 "2022-11-21T11:13:15Z")

</div>

Hi @kimpenhaus - I don’t think this is currently possible.

I had a look at the github webhook payload - it contains a list of changed files, so in theory this could be implemented (I haven’t checked for other git providers - these would need to be considered aswell).

I don’t think the drone team can commit to this in the short-medium term, but we do consider community PRs 🙂

Another workaround approach may be to create a drone step that takes the commit SHA ([DRONE\_COMMIT | Drone](https://docs.drone.io/pipeline/environment/reference/drone-commit/)) - hits a git provider endpoint to check what files are included and pass/fail the pipeline based on that.

But I appreciate a trigger means the failed build piece can be sidestepped

---

<div class="post-metadata">

### Author: ![jimsheldon](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/jimsheldon/32/7760_2.png) [@jimsheldon](https://drone.discourse.group/u/jimsheldon)
#### Post date: [November 21, 2022, 2:56pm UTC](https://drone.discourse.group/t/condition-by-file-extension-in-commit-possible/12871/3 "2022-11-21T14:56:03Z")

</div>

Hello @kimpenhaus

I think @d1wilko is right, you might be able to get what you need from the DRONE\_COMMIT sha. Also see [DRONE\_COMMIT\_BEFORE | Drone](https://docs.drone.io/pipeline/environment/reference/drone-commit-before/) and [DRONE\_COMMIT\_AFTER | Drone](https://docs.drone.io/pipeline/environment/reference/drone-commit-after/) which you could use in a `git diff` command.

I would also suggest the [pathschanged](https://github.com/meltwater/drone-convert-pathschanged) conversion extension. That extension would let you include/exclude steps based on glob pattern file changes.

---

<div class="post-metadata">

### Author: ![kimpenhaus](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/kimpenhaus/32/5665_2.png) [@kimpenhaus](https://drone.discourse.group/u/kimpenhaus)
#### Post date: [November 26, 2022, 10:40am UTC](https://drone.discourse.group/t/condition-by-file-extension-in-commit-possible/12871/4 "2022-11-26T10:40:32Z")

</div>

@d1wilko, @jimsheldon thanks for your reply - wasn’t notified so that’s why I am responding lately…

I was able to get the files from commit with following command:

```auto
git diff-tree --no-commit-id --name-only -r ${DRONE_COMMIT_SHA}

```

this is working pretty well … two more questions if you don’t mind.

1. I was struggling with having multiline commands in yml … tried | gut with no luck
2. I want to execute steps only if there is an .vcf file in the commit (mentioned that before) - saw I need to use the workspace to push sort of information from one step to the other. Is there a sort of `execute when` on a step. I just found conditions with a preset of possibilities. No idea how to check for the distance of a file in the workspace.

To give you the big picture of idea I have. In case if there is a .vcf file I want to touch a file in the workspace and execute follow-up steps only if the file is existing. Not really sure if that is good or bad - but might work 🙂

Thank you for your help and the time you took!

---

<div class="post-metadata">

### Author: ![kimpenhaus](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/kimpenhaus/32/5665_2.png) [@kimpenhaus](https://drone.discourse.group/u/kimpenhaus)
#### Post date: [November 26, 2022, 1:25pm UTC](https://drone.discourse.group/t/condition-by-file-extension-in-commit-possible/12871/5 "2022-11-26T13:25:37Z")

</div>

okay - multiline command solved… wasn’t aware it has to be like that:

```auto
    commands:
      - |
       if git diff-tree --no-commit-id --name-only -r ${DRONE_COMMIT_SHA} | grep -q ".vcf"; then
        curl -X PATCH https://my.url.com
       fi 

```

so what’s left, is to have another step only executing if the curl command was executed.
