Adding Git Commit Hashes to Email-ext Plugin in Jenkins -
i'm looking output result of jenkins build email using email-ext plugin + groovy text template.
by tweaking default groovy template (i.e., no code edits), have gotten output like:
* [] testing default post receive hook script | author: dev 1 - file: readme [change type > edit] * [] script enabled | author: dev 2 - file: readme [change type > edit] * [] custom email text tweaking | author: dev 3 - file: readme [change type > edit] i add following email:
- add hash git each change/commit
- the output of
git pull origin <branch>
i've looked @ jenkins api , email-ext plugin, being new internals of jenkins, i'm not clear on how or should looking at. , pointers appreciated!
i've made progress in regard getting commit ids. code follows, , helps others.
build info: * build result: ${build.result} * build project: ${project.name} * build url: ${rooturl}${build.url} * build date: ${it.timestampstring} * build duration: ${build.durationstring} <% def changeset = build.changeset if(changeset != null) { def hadchanges = false %> changes in build: <% changeset.each() { cs -> hadchanges = true %> <%= cs.metaclass.hasproperty('commitid') ? cs.commitid : cs.metaclass.hasproperty('revision') ? cs.revision : cs.metaclass.hasproperty('changenumber') ? cs.changenumber : "" %> <% cs.affectedfiles.each() {p -> %> [<%= cs.commitid[0..6] %>]: <%= cs.msgannotated %> | <%= cs.author %> | file: <%= p.path %> | change type: <%= p.edittype.name %> <%} } if(!hadchanges) { %> no changes <% } } %> <% if(build.result==hudson.model.result.failure) { %> console output <% build.getlog(200).each() { line -> %> ${line} <% } } %> sample output is:
[030bce6]: ready template v1 | dev 1 | file: readme | change type: edit [d4a310c]: testing git rev-list formatted email | dev 2 | file: githook | change type: edit [d4a310c]: testing git rev-list formatted email | dev 2 | file: readme | change type: edit steps configure are:
- in
$jenkins_home, create directory calledemail-templates-- directory email-ext plugin looks scripts or templates. - create file called
my-text-template.groovyin directory code above - in build's "configure" option > "add post-build action" > "editable email notifications" , in "default content", enter
${script,template="my-text-template.groovy"}
if/when figure out piece adding output of git pull origin <branch> email, shall post here.
Comments
Post a Comment