<?xml version='1.0' encoding='UTF-8'?> <matrix-project> <actions/> <description><p>
 Dynamically Created Packaging Job for a packaging repo-compatible project.
 Intended to be triggered from within a project with the packaging repo
 bootstrapped.
 </p>
 <p>
 Three parameters are expected:
 </p>
 1) File: A build parameters file that describes information about the build state
 <br>
 2) File: A tar.gz of a git bundle, created by the packaging repo, of the
 current state of the project to be packaged
 </br>
 <br>
 3) String: The project, e.g. facter, puppet
 </br>
 <p>
 This job will be triggered automatically after generation by the packaging
 repo.
 </p>
 <br>
 To trigger another downstream job after completion of this and the downstream repo creation job, pass DOWNSTREAM_JOB=$URI with the invocation, e.g.
 </br>
 <p>
 pl:jenkins:uber_build DOWNSTREAM_JOB=http://jenkins-release.delivery.puppetlabs.net/job/puppetlabs-packaging-downstream-test/build
 </p>
 <p>
 To get notified of the failure of this packaging job, pass NOTIFY= with the invocation, e.g.
 </p>
 <p>
 pl:jenkins:uber_build NOTIFY=foo@puppetlabs.com
 </p>
 <p>
 Successful completion of packaging will result in the automatic creation of
 apt/yum repositories on the distribution server with the built packages. To
 generate client apt/yum repository config files for accessing these packages,
 check out the ref of the git sha that was packaged, and run `bundle exec rake
 pl:jenkins:(deb|rpm)_repo_configs`. Configuration files will be generated and
 deposited locally in pkg/repo_configs.
 </p>
 
 
 
 </description> <logRotator class="hudson.tasks.LogRotator"> <daysToKeep>3</daysToKeep> <numToKeep>-1</numToKeep> <artifactDaysToKeep>-1</artifactDaysToKeep> <artifactNumToKeep>-1</artifactNumToKeep> </logRotator> <keepDependencies>false</keepDependencies> <properties> <jp.ikedam.jenkins.plugins.groovy__label__assignment.GroovyLabelAssignmentProperty plugin="groovy-label-assignment@1.0.0"> <groovyScript>def labelMap = [ <% if Pkg::Config.cows %> <% Pkg::Config.cows.split(' ').each do |cow| %> <% if cow =~ /cumulus/ %> "pl_deb COW=<%= cow %>": "cumulus", <% else %> "pl_deb COW=<%= cow %>": "deb", <% end %> <% end %> <% end %> <% if Pkg::Config.final_mocks %> <% Pkg::Config.final_mocks.split(' ').each do |mock| %>"pl_mock MOCK=<%= mock %>": "rpm",<% end %> <% end %> <% if Pkg::Config.build_tar then %>"package_tar": "tar",<% end %> <% if Pkg::Config.build_gem then %>"package_gem": "gem",<% end %> <% if Pkg::Config.build_dmg then %>"package_apple": "dmg",<% end %> ]; return labelMap.get(binding.getVariables().get("command"));</groovyScript> </jp.ikedam.jenkins.plugins.groovy__label__assignment.GroovyLabelAssignmentProperty> <jenkins.plugins.hipchat.HipChatNotifier_-HipChatJobProperty plugin="hipchat-plugin@0.1.0"> <room></room> <startNotification>false</startNotification> </jenkins.plugins.hipchat.HipChatNotifier_-HipChatJobProperty> <hudson.model.ParametersDefinitionProperty> <parameterDefinitions> <hudson.model.FileParameterDefinition> <name>BUILD_PROPERTIES</name> <description></description> </hudson.model.FileParameterDefinition> <hudson.model.FileParameterDefinition> <name>PROJECT_BUNDLE</name> <description></description> </hudson.model.FileParameterDefinition> <hudson.model.StringParameterDefinition> <name>PROJECT</name> <description></description> <defaultValue></defaultValue> </hudson.model.StringParameterDefinition> <hudson.model.StringParameterDefinition> <name>METRICS</name> <description></description> <defaultValue></defaultValue> </hudson.model.StringParameterDefinition> </parameterDefinitions> </hudson.model.ParametersDefinitionProperty> </properties> <scm class="hudson.scm.NullSCM"/> <canRoam>true</canRoam> <disabled>false</disabled> <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> <triggers class="vector"/> <concurrentBuild>false</concurrentBuild> <axes> <hudson.matrix.TextAxis> <name>command</name> <values> <% if Pkg::Config.cows %> <% Pkg::Config.cows.split(' ').each do |cow| %><string>pl_deb COW=<%= cow %></string><% end %> <% end %> <% if Pkg::Config.final_mocks %> <% Pkg::Config.final_mocks.split(' ').each do |mock| %><string>pl_mock MOCK=<%= mock %></string><% end %> <% end %> <% if Pkg::Config.build_tar then %><string>package_tar</string><% end %> <% if Pkg::Config.build_gem then %><string>package_gem</string><% end %> <% if Pkg::Config.build_dmg then %><string>package_apple</string><% end %> </values> </hudson.matrix.TextAxis> </axes> <builders> <hudson.tasks.Shell> <command>#!/bin/bash set -e ### Create a local clone of the git-bundle that was passed # The bundle is wrapped in a tarball. We don't need to know the project that is # in the git bundle. # Swap out _ for : in the command - lein cannot handle : in paths, and jenkins # automatically makes directories with the names of the matrix cell (in this # case $command) if https://github.com/technomancy/leiningen/issues/891 is ever # resolved, this dirty hack can be removed. command=$(echo $command | sed 's/_/:/1') [ -f "PROJECT_BUNDLE" ] || exit 1 mkdir project && tar -xzf PROJECT_BUNDLE -C project/ pushd project git clone --recursive $(ls) git_repo pushd git_repo ### Clone the packaging repo bundle install --path .bundle/gems --binstubs .bundle/bin --retry 3 ### Perform the build bundle exec rake $command PARAMS_FILE="$WORKSPACE/BUILD_PROPERTIES" --trace ### Send the results bundle exec rake pl:jenkins:ship["artifacts"] PARAMS_FILE="$WORKSPACE/BUILD_PROPERTIES" --trace popd popd</command> </hudson.tasks.Shell> </builders> <publishers> <org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder plugin="groovy-postbuild@1.8"> <groovyScript> import java.util.regex.Matcher import java.util.regex.Pattern import java.net.HttpURLConnection import java.util.Date; def get_jenkins_build_time() { start_time = manager.build.getStartTimeInMillis() end_time = new Date().getTime() return String.valueOf((end_time - start_time)/1000) } // Assemble metrics to post to build metrics server app_server = "<%= Pkg::Config.metrics_url %>" task_metrics = manager.build.getEnvironment(manager.listener)['METRICS'] charset = "UTF-8" // Maintain backwards compatibility if ( task_metrics == null) { build_user = "N/A" version = "N/A" pe_version = "N/A" build_team = "N/A" } else { build_user = task_metrics.split("~")[0] version = task_metrics.split("~")[1] pe_version = task_metrics.split("~")[2] build_team = task_metrics.split("~")[3] } matcher = manager.getLogMatcher(/(?:Finished building in:) ([\d]+\.?[\d]*)/) if (matcher != null) { package_build_time = matcher[0][1] } else { package_build_time = "N/A" } cmd_string = manager.build.getEnvironment(manager.listener)['command'] if(cmd_string =~ /deb/) { package_type = 'deb' } else if(cmd_string =~ /rpm|mock/) { package_type = 'rpm' } else if(cmd_string =~ /gem/) { package_type = 'gem' } else if(cmd_string =~ /apple/) { package_type = 'dmg' } else if(cmd_string =~ /tar/) { package_type = 'tar' } else { package_type = 'N/A' } switch (package_type) { case 'deb': dist = cmd_string.split('-')[1] break case 'rpm': if(pe_version != 'N/A') { dist = cmd_string.split('-')[2] } else { dist = cmd_string.split('-')[1] + cmd_string.split('-')[2] } break case 'gem': dist = 'gem' break case 'dmg': dist = 'apple' break case 'tar': dist = 'tar' break default: dist = 'N/A' } jenkins_build_time = get_jenkins_build_time() package_name = manager.build.getEnvironment(manager.listener)['PROJECT'] build_loc = manager.build.getEnvironment(manager.listener)['NODE_NAME'] build_log = "${manager.build.getEnvironment(manager.listener)['BUILD_URL']}" + "consoleText" success = String.valueOf(manager.build.result) String query = String.format("package_name=%s&dist=%s&package_type=%s&build_user=%s&build_team=%s&build_loc=%s&version=%s&pe_version=%s&success=%s&build_log=%s&jenkins_build_time=%s&package_build_time=%s", URLEncoder.encode(package_name, charset), URLEncoder.encode(dist, charset), URLEncoder.encode(package_type, charset), URLEncoder.encode(build_user, charset), URLEncoder.encode(build_team, charset), URLEncoder.encode(build_loc, charset), URLEncoder.encode(version, charset), URLEncoder.encode(pe_version, charset), URLEncoder.encode(success, charset), URLEncoder.encode(build_log, charset), URLEncoder.encode(jenkins_build_time, charset), URLEncoder.encode(package_build_time, charset)) // Make sure the server is listening before attempting to post data URLConnection connection = null serverAlive = false try { URL u = new URL(app_server); connection = (HttpURLConnection) u.openConnection(); connection.setRequestMethod("GET"); int code = connection.getResponseCode(); serverAlive = true connection.disconnect(); } catch (MalformedURLException e) { serverAlive = false e.printStackTrace() } catch (IOException e) { serverAlive = false e.printStackTrace() } finally { if (serverAlive == true) { connection = new URL(app_server).openConnection() connection.setDoOutput(true) // Triggers POST. connection.setRequestProperty("Accept-Charset", charset); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset); OutputStream output = null; try { output = connection.getOutputStream() output.write(query.getBytes(charset)) InputStream response = connection.getInputStream() } finally { if (output != null) try { output.close(); } catch (IOException logOrIgnore) {} } } } </groovyScript> <behavior>0</behavior> </org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder> <hudson.tasks.ArtifactArchiver> <artifacts>**/PROJECT_BUNDLE, **/BUILD_PROPERTIES</artifacts> <latestOnly>false</latestOnly> <allowEmptyArchive>false</allowEmptyArchive> </hudson.tasks.ArtifactArchiver><% if Pkg::Config.notify %> <hudson.tasks.Mailer plugin="mailer@1.4"> <recipients><%= "#{Pkg::Config.notify}" %></recipients> <dontNotifyEveryUnstableBuild>false</dontNotifyEveryUnstableBuild> <sendToIndividuals>false</sendToIndividuals> </hudson.tasks.Mailer><% end %> <hudson.plugins.parameterizedtrigger.BuildTrigger plugin="parameterized-trigger@2.16"> <configs> <hudson.plugins.parameterizedtrigger.BuildTriggerConfig> <configs> <hudson.plugins.parameterizedtrigger.CurrentBuildParameters/> </configs> <% if Pkg::Config.build_msi downstream = "#{Pkg::Config.project}-msi-#{Pkg::Config.build_date}-#{Pkg::Config.short_ref}" else downstream = "#{Pkg::Config.project}-repo-#{Pkg::Config.build_date}-#{Pkg::Config.ref}" end -%> <projects><%= downstream %></projects> <condition>ALWAYS</condition> <triggerWithNoParameters>false</triggerWithNoParameters> </hudson.plugins.parameterizedtrigger.BuildTriggerConfig> </configs> </hudson.plugins.parameterizedtrigger.BuildTrigger> </publishers> <buildWrappers> <hudson.plugins.build__timeout.BuildTimeoutWrapper plugin="build-timeout@1.11"> <timeoutMinutes>90</timeoutMinutes> <failBuild>false</failBuild> <writingDescription>false</writingDescription> <timeoutPercentage>0</timeoutPercentage> <timeoutType>absolute</timeoutType> <timeoutMinutesElasticDefault>3</timeoutMinutesElasticDefault> </hudson.plugins.build__timeout.BuildTimeoutWrapper> <hudson.plugins.ansicolor.AnsiColorBuildWrapper plugin="ansicolor@0.3.1"> <colorMapName>xterm</colorMapName> </hudson.plugins.ansicolor.AnsiColorBuildWrapper> <hudson.plugins.timestamper.TimestamperBuildWrapper plugin="timestamper@1.8.4"/> </buildWrappers> <executionStrategy class="hudson.matrix.DefaultMatrixExecutionStrategyImpl"> <runSequentially>false</runSequentially> </executionStrategy> </matrix-project>