<p>As I found may be this will helps you. With this you can fetch latest successful build change log file of any project build with Jenkins. </p>

<pre><code>$DirectoryA = "D:\Jenkins\jobs\projectName\builds"  ####Jenkind directory
$firstfolder = Get-ChildItem -Path $DirectoryA | Where-Object {$_.PSIsContainer} | Sort-Object LastWriteTime -Descending | Select-Object -First 1
$DirectoryB = $DirectoryA + "\" + $firstfolder

$sVnLoGfIle = $DirectoryB + "\" + "changelog.xml" 

write-host $sVnLoGfIle
</code></pre>

CC BY-SA 4.0
2021-04-30T02:54:52.740Z
In Jenkins\jobs\projectName\builds\75\ I don't see the last changelog file but on the Jenkins dashboard, I see the last-changes option and changes so where to find exactly this last-change file?
Ashish Karpe
CC BY-SA 4.0
2021-08-30T12:46:11.743Z
Hey @Ashish, You can find jenkins home directory path "http//:ip:8080/jenkins/configure". In that directory there must be a job`s folder. Changes reflect only for jobs not for any pipeline. 75 is just a build id into that folder you can see "changelog.xml" file
Ashu
CC BY-SA 4.0
2018-07-19T05:34:05.190Z
2018-07-19T05:34:05.190Z
Ashu
<p>You may try something like this: </p>

<pre><code>node('my_kubernetes_pod') {
    passedBuilds = []

    lastSuccessfulBuild(passedBuilds, currentBuild);

    def changeLog = getChangeLog(passedBuilds)
    echo "changeLog ${changeLog}"
}

def lastSuccessfulBuild(passedBuilds, build) {
    if ((build != null) &amp;&amp; (build.result != 'SUCCESS')) {
        passedBuilds.add(build)
        lastSuccessfulBuild(passedBuilds, build.getPreviousBuild())
    }
}

@NonCPS
def getChangeLog(passedBuilds) {
    def log = ""
    for (int x = 0; x &lt; passedBuilds.size(); x++) {
        def currentBuild = passedBuilds[x];
        def changeLogSets = currentBuild.rawBuild.changeSets
        for (int i = 0; i &lt; changeLogSets.size(); i++) {
            def entries = changeLogSets[i].items
            for (int j = 0; j &lt; entries.length; j++) {
                def entry = entries[j]
                log += "* ${entry.msg} by ${entry.author} \n"
            }
        }
    }
    return log;
}
</code></pre>

<p>Additionally, you may try out "Changes Since Last Success Plugin":
<a href="https://wiki.jenkins.io/display/JENKINS/Changes+Since+Last+Success+Plugin" rel="noreferrer">https://wiki.jenkins.io/display/JENKINS/Changes+Since+Last+Success+Plugin</a></p>

<p>But it will not work together with pipeline, this is a separate approach.</p>

CC BY-SA 3.0
2017-10-14T05:58:42.157Z
It seems this solution gives the change logs of last succesaful builds. What I actually was looking for was chnage logs (of last unsuccessful builds) since last successful build. But your answr is definitely helpful. Build.getpreviousebuuld() and recursion was what i had missed. Thank you very much for the answer.
Bee
CC BY-SA 3.0
2017-10-14T06:33:30.660Z
Always welcome ;-)
user54
CC BY-SA 3.0
2017-10-28T18:46:21.970Z
I suspect that the recursive solution might run into problems running out of stack if you had it going through a lot of builds. Wouldn't be too hard to switch to an iterative process though.
drewish
CC BY-SA 3.0
2017-10-13T21:48:17.670Z
2017-10-13T21:48:17.670Z
user54
<p>In my Jenkins pipeline, I can get change logs of the current build by this.</p>

<pre><code>def changeLogSets = currentBuild.changeSets
</code></pre>

<p>Is there a way to get all change-logs since last successful build? </p>

<jenkins><jenkins-pipeline>
Get all change logs of since last successful build in Jenkins Pipeline
Bee
# Get all change logs of since last successful build in Jenkins Pipeline

(Asked by: username_0 on 2017-10-13)

In my Jenkins pipeline, I can get change logs of the current build by this.
def changeLogSets = currentBuild.changeSets

Is there a way to get all change-logs since last successful build?

**Tags:** jenkins, jenkins-pipeline


---

## 2 answers

### Answer by username_3 on 2017-10-13. Score: 12 | Accepted answer

You may try something like this: 
node('my_kubernetes_pod') {
    passedBuilds = []

    lastSuccessfulBuild(passedBuilds, currentBuild);

    def changeLog = getChangeLog(passedBuilds)
    echo "changeLog ${changeLog}"
}

def lastSuccessfulBuild(passedBuilds, build) {
    if ((build != null) && (build.result != 'SUCCESS')) {
        passedBuilds.add(build)
        lastSuccessfulBuild(passedBuilds, build.getPreviousBuild())
    }
}

@NonCPS
def getChangeLog(passedBuilds) {
    def log = ""
    for (int x = 0; x < passedBuilds.size(); x++) {
        def currentBuild = passedBuilds[x];
        def changeLogSets = currentBuild.rawBuild.changeSets
        for (int i = 0; i < changeLogSets.size(); i++) {
            def entries = changeLogSets[i].items
            for (int j = 0; j < entries.length; j++) {
                def entry = entries[j]
                log += "* ${entry.msg} by ${entry.author} \n"
            }
        }
    }
    return log;
}

Additionally, you may try out "Changes Since Last Success Plugin":
https://wiki.jenkins.io/display/JENKINS/Changes+Since+Last+Success+Plugin
But it will not work together with pipeline, this is a separate approach.

> **Comments:**
> **username_0**: It seems this solution gives the change logs of last succesaful builds. What I actually was looking for was chnage logs (of last unsuccessful builds) since last successful build. But your answr is definitely helpful. Build.getpreviousebuuld() and recursion was what i had missed. Thank you very much for the answer.  
> **username_3**: Always welcome ;-)  
> **username_4**: I suspect that the recursive solution might run into problems running out of stack if you had it going through a lot of builds. Wouldn't be too hard to switch to an iterative process though.  

---

### Answer by username_1 on 2018-07-19. Score: 2

As I found may be this will helps you. With this you can fetch latest successful build change log file of any project build with Jenkins. 
$DirectoryA = "D:\Jenkins\jobs\projectName\builds"  ####Jenkind directory
$firstfolder = Get-ChildItem -Path $DirectoryA | Where-Object {$_.PSIsContainer} | Sort-Object LastWriteTime -Descending | Select-Object -First 1
$DirectoryB = $DirectoryA + "\" + $firstfolder

$sVnLoGfIle = $DirectoryB + "\" + "changelog.xml" 

write-host $sVnLoGfIle

> **Comments:**
> **username_2**: In Jenkins\jobs\projectName\builds\75\ I don't see the last changelog file but on the Jenkins dashboard, I see the last-changes option and changes so where to find exactly this last-change file?  
> **username_1**: Hey @Ashish, You can find jenkins home directory path "http//:ip:8080/jenkins/configure". In that directory there must be a job`s folder. Changes reflect only for jobs not for any pipeline. 75 is just a build id into that folder you can see "changelog.xml" file  

---

