Condition by file extension in commit possible?

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,

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 :slight_smile:

Another workaround approach may be to create a drone step that takes the commit SHA (DRONE_COMMIT | Drone) - 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

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 and DRONE_COMMIT_AFTER | Drone which you could use in a git diff command.

I would also suggest the pathschanged conversion extension. That extension would let you include/exclude steps based on glob pattern file changes.

@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:

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 :slight_smile:

Thank you for your help and the time you took!

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

      - |
       if git diff-tree --no-commit-id --name-only -r ${DRONE_COMMIT_SHA} | grep -q ".vcf"; then
        curl -X PATCH

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