I recently had a similar need and was able to get what I needed with the Groovy plugin (not the Groovy postbuild plugin) and a quick groovy script (seacrh the 'jenkinsci-dev' group for 'Last Successful BUILD_ID'). The script is listed below.
This would need to execute as a system groovy script (you'll see that once you install the plugin) and there is a quirk with that - it will only run on the master. I have not tested it in a master/slave situation. Anyway, basically this will 'export' the last successful build id (which is a date/time string in a known format) as a build parameter in the current run, accessable to subsequent build steps as an env var just like $BUILD_ID is.
You can retrieve more info than that, if needed. For example you can directly acess the ChangeLogSets from the current build and the last successful build, just do currentBuild.getChangeSets().getItems() or lastSuccussfulBuild.getChangeSets().getItems() and iterate. See hudson.model.AbstractBuild, hudson.model.Job and hudson.model.Run in the core for more info.
Thanks,
Ben
import hudson.model.AbstractBuild;
import hudson.model.ParametersAction;
import hudson.model.StringParameterValue;
//I suspect that if your job was started on a slave and this is running in the master then you would need to do somethin like Hudson.getInstance().getItem(jobName).something where 'something' is the way to get hold of current-running build (see the groovy script plugin page on the wiki as it has a lot of useful stuff in the comments at the bottom, like how to do just that). Never tried it - I only run on the master.
AbstractBuild currentBuild = (AbstractBuild) Thread.currentThread().executable;
//I use lastStableBuild as it will return only the lst succesful build, lastSuccessfulBuild includes both successful and stable ones. See hudson.model.Job and/or hudson.model.Run in the core for more info.
def lastStableBuild = currentBuild.getParent().getLastStableBuild();
StringParameterValue x = null;
if(lastStableBuild != null) {
String s = lastStableBuild.getId();
println "This is the last stable build id: " + s;
x = new StringParameterValue("LAST_STABLE_BUILD_ID",s);
} else {
x = new StringParameterValue("LAST_STABLE_BUILD_ID","null");
}
ParametersAction y = new ParametersAction(x);
currentBuild.addAction(y);
//check to see if it is there...
def envVars= currentBuild.properties.get("envVars");
println "This is the last stable build id: " + envVars["LAST_STABLE_BUILD_ID"];