Skip to content

Instantly share code, notes, and snippets.

@jeffryvu
Created February 12, 2015 20:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeffryvu/e67e21708c0c876a8f0d to your computer and use it in GitHub Desktop.
Save jeffryvu/e67e21708c0c876a8f0d to your computer and use it in GitHub Desktop.
Bash script to get the changelog from a certain jenkins build, format it in a nice way and write it to a properties file.
# Based on http://stackoverflow.com/questions/11823826/get-access-to-build-changelog-in-jenkins
# Get changelog and format it properly
CHANGELOG=$(curl "http://localhost:8080/job/MyProject/$UPSTREAM_BUILD_NUMBER/api/xml?wrapper=changes&xpath=//changeSet//comment" | sed -e "s/<\/comment>//g; s/<comment>/* /g; s/<\/*changes>//g" | sed '/^$/d;G')
# Write result to properties file
echo CHANGELOG=$CHANGELOG > build.properties
@adjokovic
Copy link

Thanks for the post. However I am still getting an empty file. I have changed UPSTREAM_BUILD_NUMBER to BUILD_NUMBER, and I have changed local host to the http link to the job ${JOB_URL}${BUILD_NUMBER}. Those are environment variables provided by Jenkins.

The string is located in 'execute shell' portion of the build section of Jenkins, after Xcode executes.

Change log comes back empty. Any suggestion is super helpful. Thanks

@jeffryvu
Copy link
Author

jeffryvu commented Apr 2, 2015

Have you tried to just paste the url in a browser and see the result? If you have put this script in a downstream job like I do in the post, you really need to use the UPSTREAM_BUILD_NUMBER, otherwise you're getting the changelog from the current job which is empty.

@narendramannam
Copy link

how do i conver this properties file to html view only comments and id to show

@saisudhakar
Copy link

is there a way to get the changelog between a build to the other? Is there an xml exposed by Jenkins?

@vinodakumarsr
Copy link

Its working but format is not same

@kamildziadekpwr
Copy link

Thank you so much for this command! I was not aware that the job can be queried with XPath. I have tweaked it a little bit so that it drops the current build changelog to a variable.

CHANGELOG=$(curl "$BUILD_URL/api/xml?wrapper=changes&xpath=//changeSet//comment" | sed -e "s/<\/comment>//g; s/<comment>/* /g; s/<\/*changes>//g" | sed '/^$/d;G')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment