How to get list of changed files since last build in Jenkins/Hudson

后端 未结 11 1976
时光取名叫无心
时光取名叫无心 2020-11-28 09:35

I have set up Jenkins, but I would like to find out what files were added/changed between the current build and the previous build. I\'d like to run some long running tests

11条回答
  •  清酒与你
    2020-11-28 10:20

    #!/bin/bash
    
    set -e
    
    job_name="whatever"
    JOB_URL="http://myserver:8080/job/${job_name}/"
    FILTER_PATH="path/to/folder/to/monitor"
    
    python_func="import json, sys
    obj = json.loads(sys.stdin.read())
    ch_list = obj['changeSet']['items']
    _list = [ j['affectedPaths'] for j in ch_list ]
    for outer in _list:
      for inner in outer:
        print inner
    "
    
    _affected_files=`curl --silent ${JOB_URL}${BUILD_NUMBER}'/api/json' | python -c "$python_func"`
    
    if [ -z "`echo \"$_affected_files\" | grep \"${FILTER_PATH}\"`" ]; then
      echo "[INFO] no changes detected in ${FILTER_PATH}"
      exit 0
    else
      echo "[INFO] changed files detected: "
      for a_file in `echo "$_affected_files" | grep "${FILTER_PATH}"`; do
        echo "    $a_file"
      done;
    fi;
    

    It is slightly different - I needed a script for Git on a particular folder... So, I wrote a check based on jollychang.

    It can be added directly to the job's exec shell script. If no files are detected it will exit 0, i.e. SUCCESS... this way you can always trigger on check-ins to the repository, but build when files in the folder of interest change.

    But... If you wanted to build on-demand (i.e. clicking Build Now) with the changed from the last build.. you would change _affected_files to:

    _affected_files=`curl --silent $JOB_URL'lastSuccessfulBuild/api/json' | python -c "$python_func"`
    

提交回复
热议问题