Kishore Tamire
Kishore Tamire

Reputation: 2074

jenkins plugin for triggering build whenever any file changed in a given directory

I am looking for functionality where we have a directory with some files in it.

Whenever any one makes a change in any of the files in the directory, jenkins shoukd trigger a build.

Is there any plugin or mathod for this functionality. Please advise.

Thanks in advance.

Upvotes: 1

Views: 6381

Answers (2)

hhony
hhony

Reputation: 351

Although slightly related.. it seems like this issue was about monitoring static files on system.. however there are many version control systems for just this purpose.

I answered this in another post if you're using git to track changes on the files themselves:

#!/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;

You can add the check directly to the top of the job's exec shell, and it will exit 0 if no changes detected.. Hence, you can always poll the top level of the repo for check-in's to trigger a build. And only complete a build if the files in question change.

Upvotes: 1

Anders Lindahl
Anders Lindahl

Reputation: 42870

I have not tried it myself, but The FSTrigger plugin seems to do what you want:

FSTrigger provides polling mechanisms to monitor a file system and trigger a build if a file or a set of files have changed.

If you can monitor the directory with a script, you can trigger the build with a HTTP GET, for example with wget or curl:

wget -O- $JENKINS_URL/job/JOBNAME/build 

Upvotes: 4

Related Questions