Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

circleCI - How to run job when has change in specific directory

I'm using circleCI version 2 and my config.yml like this:

version: 2
jobs:
   a:
     steps:...
   b:
     steps:...
workflows:
  version: 2
  main_pipeline:
    jobs:
       - a
       - b

I want only to build when a change happens in the directory.

job a for folder a job b for folder b

when folder a changes, build only job a.

like image 641
MrNonz Avatar asked Oct 29 '22 05:10

MrNonz


2 Answers

function trigger_job() {
    job_name=$1
    curl --user ${CIRCLE_API_TOKEN}: \
        --data build_parameters[CIRCLE_JOB]=$job_name \
        --data revision=$CIRCLE_SHA1 \
https://circleci.com/api/v1.1/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/tree/$CIRCLE_BRANCH

I use this function for trigger job and find different by git-diff like this git diff-tree --name-only $(git log -n 2 --pretty=format:"%H") | grep project

like image 55
MrNonz Avatar answered Nov 13 '22 04:11

MrNonz


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.

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

You can also check out our config

like image 26
kuzdogan Avatar answered Nov 13 '22 05:11

kuzdogan