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

后端 未结 8 1573
后悔当初
后悔当初 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

    If the logic for choosing the files is not trivial, I would trigger script execution on each change and then write a script to check if indeed a build is required, then triggering a build if it is.

    0 讨论(0)
  • 2020-11-28 20:37

    Basically, you need two jobs. One to check whether files changed and one to do the actual build:

    Job #1

    This should be triggered on changes in your Git repository. It then tests whether the path you specify ("src" here) has changes and then uses Jenkins' CLI to trigger a second job.

    export JENKINS_CLI="java -jar /var/run/jenkins/war/WEB-INF/jenkins-cli.jar"
    export JENKINS_URL=http://localhost:8080/
    export GIT_REVISION=`git rev-parse HEAD`
    export STATUSFILE=$WORKSPACE/status_$BUILD_ID.txt
    
    # Figure out, whether "src" has changed in the last commit
    git diff-tree --name-only HEAD | grep src
    
    # Exit with success if it didn't
    $? || exit 0
    
    # Trigger second job
    $JENKINS_CLI build job2 -p GIT_REVISION=$GIT_REVISION -s
    

    Job #2

    Configure this job to take a parameter GIT_REVISION like so, to make sure you're building exactly the revision the first job chose to build.

    Parameterized build string parameter Parameterized build Git checkout

    0 讨论(0)
提交回复
热议问题