Trigger a build only if a single folder/file is changed

Hi Team,

I have a requirement: I want the Buildkite job to run only if there is a change in the folder containing the Dockerfile.

I found a solution showing a 2 job solution, first serving as a watcher and the other as an actual build. But I don’t want an overhead job.

Please suggest a better way to do it. Thanks!

Regards,
Ismail

Hey @ismail good question. I’m not sure what you are referring to with “2 job solution”, but one way to achieve this is our diff plugin: GitHub - buildkite-plugins/monorepo-diff-buildkite-plugin: Run separate pipelines for each folder in your monorepo

You can detect changes in file paths and then run steps based on changes to those paths

Hi Jarryd,

I have tried that repo and it fails to achieve my needs, here is the code in use reference:

env:
  PE_IMAGE_VERSION: "2.0.0"

steps:  
  - label: "Build Docker Image :docker:"
    plugins:
      - monorepo-diff#v1.0.1:
          # diff: "git diff --name-only HEAD~1"
          watch:
            - path: /path/to/docker/
              config:
                command: "cd /path/to/docker && docker build -t ${ECR_REPO_BASE_URL}/my-image:${PE_IMAGE_VERSION} . && docker push ${ECR_REPO_BASE_URL}/my-image:${PE_IMAGE_VERSION}"
      - ecr#v2.9.0:
          login: true

Now this keeps failing to push because ecr login runs in "Build Docker Image :docker:" step and docker build happens in another

P.S. I have tried changing order of the plugins but still the same

Hello, @ismail! Could you please send a link to a build where you see this issue happening to support@buildkite.com for us to be able to take a closer look?
Thanks!

Karen

Shared details over email

1 Like