Ok, the specifics:
Our Setup:
We have a master Jenkins scheduled job that calls all of the individual autopkg software jobs (unscheduled) in Jenkins, every 3 hours M-F, 7am - 10pm. Having individual small jobs makes it easy to tell which software download/pkg/munki import is broken/not
working (FYI, this technique doesn't work with aamporter: all your adobe plists need to be called at once to get --munkiimport to have the proper 'update_for' for updates that impact multiple adobe apps).
The trick is that your last job of the bunch is the 'autopkg run recipe.munki.MakeCatalogs' (we also have that setup as a Jenkins job). When you run an individual job by hand you either have to remember to do that manually or add it to each of the individual
jobs post-build section. Iif you don't have logic built to separate manual jobs from the scheduled/timer jobs (we don't yet), your timer job ends up running MakeCatalogs A LOT more than necessary. If you fail to run the autopkg MakeCatalogs recipe manually
when run a jenkins job outside of your timed master job you get a lot of __1, __2 duplication in your software repository (pkgs & pkgsinfo). So far I've opted for the "make the computer do waaaay more work than it should need to" by putting it at the end
of all the little jobs AND at the end of the big job. Eventually I might figure out the logic of having a job run based on whether it was NOT called by the timer function. But for now it works.
I like Jenkins as it gives both a simple and attractive high level overview of success/brokenness (good for demos to co-workers/boss: sunny/blue = good, grey/cloudy = iffy, stormy/red = bad), scheduling and does this for both autopkg, aaimporter AND other
scheduled jobs (we're looking at using it for a remote backup using rsync) -- you can see what broke, what the log file / command line output for the jobs are split out for each software recipe, and you can test/build it quickly. And now e-mail notification
;-)
Setting up Email-ext:
Each individual small job (individual software recipe) under its
Configure/Configuration page at the bottom is the
Editable Email Notification and most are set to the defaults, with the exception of the Grey
Advanced Settings... button: this is set to Pre-send Script field = $DEFAULT_PRESEND_SCRIPT (which I'm pretty sure is the default) and the Triggers are set to
Failure - Any, Send To Recipient List and an additional trigger
Success Send To Recipient List.
Under the main
Manage Jenkins ->
Configure System page:
I set the
System Admin e-mail address field to MacUpdates @ Servername (Jenkins) <my-email@address> as that is what appears in the FROM: field for notifications of new software imported/downloaded and failed jobs. Under
Extended E-mail Notification we like plain text for the Default Content Type,
Default Recipients is set to a comma separated list of our mac admin team members,
Default Subject is $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS! (this may also be a default setting) and the
Default Content field is set to ${SCRIPT, template="autopkg-munki-new-items.groovy"} This script (autopkg-munki-new-items.groovy) lives in Jenkins/Home/email-templates and is attached below after the Default Pre-send Script.
The crux was figuring out that the e-mail template must be teamed up with a Default Pre-send Script as the cancel = true that is supposed to kill the sending of the e-mail that we asked to be triggered for a successful Jenkins job BUT that did no real work
so does not need to report in. For some reason it wasn't working from within the template. Even so I left it in the template as that is the logical place for it, and later I may try to move it back there not realizing I've been down that road.
As mentioned before, this works but I don't claim to be a groovy java coder ;-) And it would be nice to have something similar for aamporter... hmm...
M@
================ Default Pre-send Script ======================
// Load up the first 1000 lines of the log file into a variable
def log = build.getLog(1000)
// Let's setup a boolean of the result of searching for the string that appears
// in the log file when a job successfully completes but no work occurred.
def NothingDone = log =~ /Nothing downloaded, packaged or imported/
// And now let's test against that boolean and kill the e-mail (cancel = true) if it found the
// "Nothing downloaded, packaged or imported" string
if (NothingDone) {
// Build is successful, but nothing imported... so no e-mail
cancel=true;
}
// Else run the script in the template in the Default Content.
======== Jenkins/Home/email-templates/autopkg-munki-new-items.groovy (the Default Content script) ===========
GENERAL INFO
BUILD ${build.result}
Build URL: ${rooturl}${build.url}
Project: ${
project.name}
Date of build: ${it.timestampString}
Build duration: ${build.durationString}
<%
import java.util.regex.*
def log = build.getLog(1000)
def NewItemsImportedSearch = log =~ /new items were imported/
def NewItemsDownloaded = log =~ /new items were downloaded/
def NothingDone = log =~ /Nothing downloaded, packaged or imported/
if (NothingDone) {
// Build is successful, but nothing imported... so no e-mail
cancel=true;
// M@ 17Oct2014: THIS IS BEING HANDLED BY A PRE-SEND SCRIPT
// as it seemed to do no good here :-(
%>
Nothing downloaded, packaged or imported... SO WHY ARE WE SEEING THIS E-MAIL?!?@#??%??!
<%
} else if (NewItemsImportedSearch) {
%>
NEW ITEM AVAILABLE IN MUNKI
A new version of ${
project.name} was downloaded (autopkg: /Users/Shared/AutoPkg/Cache/${
project.name} and imported into the munki repository (/Users/Shared/munki_repo/pkgs/).
<%
} else if (NewItemsDownloaded) {
%>
NEW ITEM DOWNLOADED TO AutoPkg Cache
A new version of ${
project.name} was downloaded to the AutoPkg Cache -- (autopkg: /Users/Shared/AutoPkg/Cache/${
project.name} BUT NOT imported into the munki repository.
<%
} else {
%>
FAILURE?
<%
}
%>
CONSOLE OUTPUT
<% log.each()
{ line -> %>
${line}
<% }
%>
From: Childress, Matt
Sent: Monday, October 20, 2014 9:18 PM
To: <autopkg...@googlegroups.com>
Subject: Re: [autopkg-discuss] Re: Those of you using Jenkins and Autopkg