How to trigger a build only if changes happen on particular set of files

后端 未结 8 1618
后悔当初
后悔当初 2020-11-28 20:01

How do I tell Jenkins/Hudson to trigger a build only for changes on a particular project in my Git tree?

8条回答
  •  天涯浪人
    2020-11-28 20:36

    While this doesn't affect single jobs, you can use this script to ignore certain steps if the latest commit did not contain any changes:

    /*
     * Check a folder if changed in the latest commit.
     * Returns true if changed, or false if no changes.
     */
    def checkFolderForDiffs(path) {
        try {
            // git diff will return 1 for changes (failure) which is caught in catch, or
            // 0 meaning no changes 
            sh "git diff --quiet --exit-code HEAD~1..HEAD ${path}"
            return false
        } catch (err) {
            return true
        }
    }
    
    if ( checkFolderForDiffs('api/') ) {
        //API folder changed, run steps here
    }
    

提交回复
热议问题