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

Related searches

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 depending on whether or not certain parts of the source tree were changed.

Having scoured the Internet I can find no mention of this ability within Hudson/Jenkins though suggestions were made to use SVN post-commit hooks. Maybe it's so simple that everyone (except me) knows how to do it!

Is this possible?

The CI server will show you the list of changes, if you are polling for changes and using SVN update. However, you seem to want to be changing the behaviour of the build depending on which files were modified. I don't think there is any out-of-the-box way to do that with Jenkins alone.

A post-commit hook is a reasonable idea. You could parameterize the job, and have your hook script launch the build with the parameter value set according to the changes committed. I'm not sure how difficult that might be for you.

However, you may want to consider splitting this into two separate jobs - one that runs on every commit, and a separate one for the long-running tests that you don't always need. Personally I prefer to keep job behaviour consistent between executions. Otherwise traceability suffers.

Only modified files in Jenkins, 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� Is there any mechanism I can get the changes between two builds in Jenkins in git/gerrit environment, I am getting all changes using all changes plugin, but I want get a nice set of change between build say 1 and 2, and send an email.

I have done it the following way. I am not sure if that is the right way, but it seems to be working. You need to get the Jenkins Groovy plugin installed and do the following script.

import hudson.model.*;
import hudson.util.*;
import hudson.scm.*;
import hudson.plugins.accurev.*

def thr = Thread.currentThread();
def build = thr?.executable;

def changeSet= build.getChangeSet();

changeSet.getItems();

ChangeSet.getItems() gives you the changes. Since I use accurev, I did List<AccurevTransaction> accurevTransList = changeSet.getItems();.

Here, the modified list contains duplicate files/names if it has been committed more than once during the current build window.

how to get list of all modified files in pipeline jenkins?, For a custom Jenkins build I needed to know all changed files since the last green build. I searched a Getting all builds since the last successful one. I want all In the end the list of changed files is saved as text changed_files.log into the workspace. AbstractBuild getChangeSet method hudson.model. E.g. you can use this data to get a list of all changed files since the last successful build. I have put this into a complete example Jenkinsfile Gist to show how it fits together in context. A possible improvement would be to use a Java/Groovy native Git library instead of shelling out to a sh step.

echo $SVN_REVISION
svn_last_successful_build_revision=`curl $JOB_URL'lastSuccessfulBuild/api/json' | python -c 'import json,sys;obj=json.loads(sys.stdin.read());print obj["'"changeSet"'"]["'"revisions"'"][0]["'"revision"'"]'`
diff=`svn di -r$SVN_REVISION:$svn_last_successful_build_revision --summarize`

Last Changes Plugin - Jenkins, I'm using multibranch pipeline and i need to get the list of modified files. build: My function, which creates a string from all the changes (to be used by Possible duplicate of How to get list of changed files since last build in Jenkins/ Hudson. This will tell you all changed files since last commited build. To know more about git-whatchanged command: https://git-scm.com/docs/git-whatchanged/1.8.3. Also, if you want to know the changes of previous commit only, the modified command is: git whatchanged -n 1. Hope this help.

You can use the Jenkins Remote Access API to get a machine-readable description of the current build, including its full change set. The subtlety here is that if you have a 'quiet period' configured, Jenkins may batch multiple commits to the same repository into a single build, so relying on a single revision number is a bit naive.

I like to keep my Subversion post-commit hooks relatively simple and hand things off to the CI server. To do this, I use wget to trigger the build, something like this...

/usr/bin/wget --output-document "-" --timeout=2 \
    https://ci.example.com/jenkins/job/JOBID/build?token=MYTOKEN

The job is then configured on the Jenkins side to execute a Python script that leverages the BUILD_URL environment variable and constructs the URL for the API from that. The URL ends up looking like this:

https://ci.example.com/jenkins/job/JOBID/BUILDID/api/json/

Here's some sample Python code that could be run inside the shell script. I've left out any error handling or HTTP authentication stuff to keep things readable here.

import os
import json
import urllib2


# Make the URL 
build_url = os.environ['BUILD_URL']
api = build_url + 'api/json/'

# Call the Jenkins server and figured out what changed
f = urllib2.urlopen(api)
build = json.loads(f.read())
change_set = build['changeSet']
items = change_set['items']
touched = []
for item in items:
    touched += item['affectedPaths']

The plugin uses diff2html to show last changes of a given build via VCS diffs, To get most from this plugin use periodically SCM pooling to trigger your builds, node { stage ('Build') { svn 'https://subversion.assembla.com/svn/cucumber-json -files/trunk/' #34 Show the list of commits between current and previous revision. Dismiss Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Using the Build Flow plugin and Git:

final changeSet = build.getChangeSet()
final changeSetIterator = changeSet.iterator()
while (changeSetIterator.hasNext()) {
  final gitChangeSet = changeSetIterator.next()
  for (final path : gitChangeSet.getPaths()) {
    println path.getPath()
  }
}

gitChangelog : Changelog from Git repository The following plugin provides How to get list of changed files since last build in Jenkins/Hudson , The CI server � How to deploy only modified/new files GIT+Jenkins+PHP?, 2 Answers. You need two things: The commit of the previous build and then the changed files between the previous build commit and current HEAD. For the first: There might be ways to find the commit from Jenkins via the REST API (as it does display it in the build page. Build SASS or LESS

The possible values for Since attribute is Previous revision (the default), Last successful build and Last tag. If SpecificRevision parameter is provided then Since configuration will be ignored and the diff will be done with provided revision id.

For look the commit (like it looks on git log view) with the list of files included in, use: git show --name-only [commit-id_A]^.. [commit-id_B] Where [commit-id_A] is the initial commit and [commit-id_B] is the last commit than you want to show. Special attention with ^ symbol.

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 :

Comments
  • "you seem to want to be changing the behaviour of the build depending on which files were modified" That is done, for example, with Maven incremental builds (plugin).
  • Used your code to come to this solution: stackoverflow.com/a/12939663/734687, thanks a lot!
  • if the safe navigation (?) operator is used on thr, isn't it possible that build could be null, and then you'd get a null pointer exception at build.getChangeSet() the next line down?
  • can you please explain how to do this and where? your solution seems to be the one i am looking for but i don't know how to implement it.
  • @user1725378 run in build shell for subversion only
  • Is there a way to get the absolute path of the file? This gives the path relative to the repository, so I can't figure out what repository the file was in.
  • I don't know off the top of my head. You'll have to go through the source, github.com/jenkinsci/git-plugin/blob/master/src/main/java/…, and/or experiment yourself.
  • Build Flow Plugin is now deprecated, for me (Jenkins 2.89) this solution is not working.