<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 `rake pl:jenkins:(deb|rpm)_repo_configs`. Configuration files will be generated and deposited locally in pkg/repo_configs. </p> 3 -1 -1 -1 false 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": "rpm",<% 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")); false BUILD_PROPERTIES PROJECT_BUNDLE PROJECT METRICS true false false false false command <% if Pkg::Config.cows %> <% Pkg::Config.cows.split(' ').each do |cow| %>pl_deb COW=<%= cow %><% end %> <% end %> <% if Pkg::Config.final_mocks %> <% Pkg::Config.final_mocks.split(' ').each do |mock| %>pl_mock MOCK=<%= mock %><% end %> <% end %> <% if Pkg::Config.build_tar then %>package_tar<% end %> <% if Pkg::Config.build_gem then %>package_gem<% end %> <% if Pkg::Config.build_dmg then %>package_apple<% end %> #!/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 rake package:bootstrap ### Perform the build rake $command PARAMS_FILE="$WORKSPACE/BUILD_PROPERTIES" --trace ### Send the results rake pl:jenkins:ship["artifacts"] PARAMS_FILE="$WORKSPACE/BUILD_PROPERTIES" --trace popd popd 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) {} } } } 0 **/PROJECT_BUNDLE, **/BUILD_PROPERTIES false false <% if Pkg::Config.notify %> <%= "#{Pkg::Config.notify}" %> false false <% end %> <% 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 -%> <%= downstream %> ALWAYS false 90 false false 0 absolute 3 xterm false