Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get access to Build Changelog in Jenkins

I've been pulling my hair out trying to find a way to include the list of changes generated by Jenkins (from the SVN pull) into our Testflight notes. I'm using the Testflight Plugin, which has a field for notes - but there doesn't seem to be any paramater/token that jenkins creates to embed that information.

Has anyone had any luck accomplishing something like this?

like image 439
Jim Weinhart Avatar asked Aug 06 '12 07:08

Jim Weinhart


People also ask

What is Jenkins changelog?

Git Changelog PluginCreates a changelog, or release notes, based on Git commits between 2 revisions. This can also be done with a command line tool.

Which Jenkins command to get the list of changed files?

You can also do this: git diff --name-only $GIT_PREVIOUS_COMMIT $GIT_COMMIT in your build script, pipe it to a file and you should have the list of all the files that have changed in that particular build. This is assuming you are using the Git Plugin for Jenkins.

What is latest version of Jenkins?

At the moment, the Jenkins releases 2.332. 4 and 2.346.


2 Answers

It looks like the TestFlight Plugin expands variables placed into the "Build Notes" field, so the question is: how can we get the changes for the current build into an environment variable?

As far as I'm aware, the Subversion plugin doesn't provide this information via an environment variable. However, all Jenkins SCM plugins integrate changelog information, as you can see via the "Changes" link in the web UI for each build.

This information is also available via the Jenkins API, even while a build is in progress.

For example, if you add an "Execute shell" build step where you run this command:

curl -s "http://jenkins/job/my-job/$BUILD_NUMBER/api/xml?wrapper=changes&xpath=//changeSet//comment" 

You'll get an XML document similar to this:

<changes>   <comment>First commit.</comment>   <comment>Second commit.</comment> </changes> 

You can then format this information however you like and place it into an environment variable which can then be referenced in the TestFlight "Build Notes" section.

However, setting an environment variable in a build step isn't persistent by default — to do so requires using the EnvInject Plugin.

In this case, you could write your changelog text to a temporary file with contents like:

CHANGELOG="New in this build:\n- First commit.\n- Second commit." 

Then, by using a build step with the Environment Properties File Path option to load this file, the $CHANGELOG variable would exist in your environment and persist until the end of the build, allowing you to use it in the "Build Notes" field.


Note: I haven't used the TestFlight plugin myself (though I took a quick look at the code), and I only tested the changes API with a Git repository. Similarly, I didn't test how newlines should be encoded with the EnvInject plugin, so that could cause issues.

like image 200
Christopher Orr Avatar answered Sep 19 '22 07:09

Christopher Orr


Given that Jenkins log changed format, I updated XML content from the original post. Also, since original TestFlight died, and the plugin is now obsolete, I am shoving the content into an HTML file for use with HockeyKit. It is really a text file WITH line breaks. Making sed insert line breaks is ..challenging, and the string looks very confusing (at least to me) at a first glance.

#for distribution in projects Changelog=$(curl "${BUILD_URL}api/xml?wrapper=changes&xpath=//changeSet//item//msg" | sed -e "s/<\/msg>//g; s/<msg>/\\`echo -e '\r'`/g; s/<\/*changes>//g" )  # Write result to properties file echo -e "$Changelog" > "${BuildDestinationPath}/"${BUILD_NUMBER}.html 

Note Edit: BuildDestinationPath and Changelog are my local variables. Variables in caps are Jenkins environment variables and should exist on any instalation.

like image 20
Andreja Djokovic Avatar answered Sep 21 '22 07:09

Andreja Djokovic