How to get the list of changes since the last successful build via script

291 views
Skip to first unread message

meh....@gmail.com

unread,
Mar 13, 2018, 12:20:57 PM3/13/18
to Jenkins Users
I'm fairly new to Jenkins, although my workplace has been using it for some time for automated builds.
We are using Jenkins version 2.60.1

I've been asked to help our build team by writing a script to execute during/after a build which will get all the changes since the last successful build and parse it, pulling out JIRA/Rally ticket numbers and doing something interesting with them.

I'm not sure where to start. I can see that when I look at a completed build, there is a menu item on the left called Changes and when I click on that, I see the list of Git commits which went into this build.

Where can I create a script which will get this list and give me some ability to parse it and do something with it (I'm not sure what they want to do yet - perhaps send an e-mail or create an information page which would be shown in Jenkins, if that's even possible)?

Do I add something to the build's configuration? In there I see General, Source Code Management, Build Triggers, Build Environment, Build and Post-build Actions.

Please let me know if you would like more information about what we're trying to do.

Thanks for any pointers.

meh....@gmail.com

unread,
Mar 14, 2018, 10:01:59 AM3/14/18
to Jenkins Users
Okay, I think I've figured out the big questions.

First, I need to create a build step using "Execute system Groovy script" as the type. This will execute within the JVM running Jenkins and will have access to the Jenkins build information.

Next, I can gain access to the current build using the following:
build =Thread.currentThread().executable

Now, I can walk through the builds and access the change sets for each, as in the following:
def changes = "Changes:\n"
while ( build != null && build.result != 'SUCCESS' ) {
    changes
+= "In ${build.id}:\n"
   
for ( changeLog in build.changeSets) {
       
for ( entry in changeLog.items ) {
            change
+= "${entry.msg}\n"
       
}
   
}
}

I then found the Javadoc for the Jenkins API here: http://javadoc.jenkins-ci.org/index.html?hudson and from there I was able to determine the members of each class, etc.

Thanks for your considerations.




Reply all
Reply to author
Forward
0 new messages