39

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?

Jim Weinhart
  • 395
  • 1
  • 3
  • 5
  • I needed the exact same thing. Thank you for asking this question, and I'm even more grateful for the answer. – makdad Sep 06 '12 at 02:43

6 Answers6

35

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.

Christopher Orr
  • 110,418
  • 27
  • 198
  • 193
  • 1
    Thank you so much, Christopher! – Jim Weinhart Aug 08 '12 at 01:54
  • 6
    BTW, "you can then format this information however you like" -- I used: `sed -e "s/<\/*comment>//g" | sed '/^$/d;G'` to strip out the XML `` tags and clean up the newlines. – makdad Sep 06 '12 at 03:03
  • To get a clean output of multiple change messages, I used this variation on @makdad's: `sed -e "s/<\/comment>//g; s//\t* /g; s/<\/*changes>//g" | sed '/^$/d;G'` – Greg Haygood Feb 22 '14 at 17:01
  • how to save this log into local variable? – dollar2048 Jan 12 '15 at 11:24
  • 2
    Surely there must a simpler way to access this information without this workaround by now? – IanWatson Feb 25 '15 at 19:13
  • This works for me, with one problem. If I execute this code: `CHANGELOG=$(curl "http://localhost:8080/job/myproject/$UPSTREAM_BUILD_NUMBER/api/xml?wrapper=changes&xpath=//changeSet//comment" | sed -e "s/<\/comment>//g; s//* /g; s/<\/*changes>//g" | sed '/^$/d;G') echo $CHANGELOG` The $CHANGELOG contains a list of all the files and folders in the current folder AND the changelog. How do the files/folders from the current folder show up in this variable?? – Jeffry van de Vuurst Feb 27 '15 at 14:41
  • There's a Jenkins plugin (unreleased) which does this now. See https://github.com/daniel-beck/changelog-environment-plugin and https://issues.jenkins-ci.org/browse/JENKINS-12032?focusedCommentId=242378 – Christopher Orr Feb 17 '16 at 00:06
  • @ChristopherOrr Has the plugin been published yet? – Chris Giddings Apr 19 '17 at 15:11
8

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.

4

I am using this one found here: http://jenkins.361315.n4.nabble.com/Get-SVN-changes-td3511042.html

${CHANGES, showPaths=true}

Very simple and it works for SVN.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
ferventcoder
  • 11,952
  • 3
  • 57
  • 90
  • 2
    This seems to be a feature of the email-ext plugin, so it would work for sending the changelog in an email, but not elsewhere. – Christopher Orr Jul 11 '15 at 13:47
2

I made some python example which coverts xml to CHANGELOGS

note.xml should be

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

actual python code is below

from xml.etree.ElementTree import parse
tree = parse("note.xml")
root = tree.getroot()
sentence = 'CHANGELOG =\"' 
cnt = 1
for element in root.findall('msg'):
    tempstring = element.text
    tempstring =str(cnt)+'. '+'\\n'.join(tempstring.splitlines())
    sentence =sentence +tempstring +'\\n'
    cnt = cnt +1
sentence = sentence + '\"'
print sentence
AnneTheAgile
  • 9,932
  • 6
  • 52
  • 48
I.C.Baek
  • 21
  • 6
2

In fact, you can access to that information before the build phase finish by reading/parsing the ../builds/$BUILD_NUMBER/changelog.xml file inside the build folder. This file is created with the SVN/GIT commit triggering and not with the end of the build or post_build phase. That means, you can parse it at the start of the build phase of the same job with a script and insert the data in env variables.

This is if you don´t want to use the curl and XML.

Joniale
  • 515
  • 4
  • 17
0

The Testflight Plugin has an option for this. Here's the commit:

https://github.com/jenkinsci/testflight-plugin/commit/e8edfef012d4bdefb95ee24818891a27ac920a36

I didn't see it in the most recent testflight-plugin release so I built the plugin from git and it has this option.

enter image description here

Kirby Todd
  • 11,254
  • 3
  • 32
  • 60