flux0987
flux0987

Reputation: 87

How to run a CircleCI job in a github repo only if a file in the same repo is added a new entry?

I have added a job in the existing circleci workflow, I would like to run that job only if a yaml file is changed in the repo. Is there any way to do it ? TIA.

Upvotes: 2

Views: 1711

Answers (3)

kuzdogan
kuzdogan

Reputation: 835

Yes this is now possible. CircleCI now has support for dynamic configs (instead of a single static config file), and with that a path-filtering orb is available that can detect changes under a folder and set pipeline parameters accordingly. You can set a pipeline parameter when changes are detected under a folder and add a when condition attribute with that pipeline parameter in the job.

See https://circleci.com/docs/2.0/using-dynamic-configuration/#execute-specific-workflows-or-steps-based-on-which-files-are-modified

Upvotes: 1

FelicianoTech
FelicianoTech

Reputation: 4017

No. There's no way to do that. You can follow @crack_iT's answer as that's the closest but technically the job still runs. The only option is to end the job early.

Upvotes: 1

Mesar ali
Mesar ali

Reputation: 1898

you can detect changes in circlci build step and run job only if yml files changed

- run: |
    git show --name-only ${CIRCLE_SHA1} | grep .yml

    if [ $? -eq 0 ]; then 
      echo "yml files changed" 
      // Do your job steps
    fi

Upvotes: 2

Related Questions