Skip to content

Commit

Permalink
Merge pull request #111 from jenkinsci/JENKINS-38670
Browse files Browse the repository at this point in the history
Refactor build card into extensible class
  • Loading branch information
dalvizu committed Jun 19, 2017
2 parents 6fab1fd + 6300e17 commit 15b7b6a
Show file tree
Hide file tree
Showing 16 changed files with 1,006 additions and 543 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -0,0 +1,64 @@
/*
* The MIT License
*
* Copyright (c) 2016 the Jenkins project
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package au.com.centrumsystems.hudson.plugin.buildpipeline.extension;

import hudson.Extension;
import hudson.model.Descriptor;
import org.kohsuke.stapler.DataBoundConstructor;


/**
* @author dalvizu
*/
@Extension
public class StandardBuildCard
extends BuildCardExtension {

/**
* Default constructor
*/
@DataBoundConstructor
public StandardBuildCard() {

}

@Override
public long getIndex() {
return 0;
}

/**
* Descriptor, since we're in the UI
*/
@Extension
public static class DescriptorImpl
extends Descriptor<BuildCardExtension> {

@Override
public String getDisplayName() {
return "Standard build card";
}
}
}
Expand Up @@ -18,147 +18,9 @@
<script src="${rootURL}/plugin/build-pipeline-plugin/js/build-pipeline.js"></script>

<script id="build-card-template" type="text/x-handlebars-template">
<div class="build-card rounded {{build.status}} {{#if project.disabled}}disabled{{/if}}">
<div class="header">
<a href="${rootURL}/{{build.url}}" title="{{project.name}}">
{{#unless build.isPending}}
{{#unless build.isReadyToBeManuallyBuilt}}
{{#if build.displayName}}
{{build.displayName}}
{{else}}
#{{build.number}}
{{/if}}
{{/unless}}
{{/unless}}
{{#if project.displayName}}
{{project.displayName}}
{{else}}
{{project.name}}
{{/if}}
</a>
</div>
<div class="build-info">
<ul>
{{#if build.startDate}}
<li class="build-time" title="Start date: {{build.startDate}} {{build.startTime}}">{{build.startDate}} {{build.startTime}}</li>
{{else}}
<li class="build-time"><abbr title="Not Applicable">N/A</abbr></li>
{{/if}}

{{#if build.isBuilding}}
<li class="build-duration" title="Build duration: {{build.duration}}">{{build.duration}}</li>
{{else}}
{{#if build.isComplete}}
<li class="build-duration" title="Build duration: {{build.duration}}">{{build.duration}}</li>
{{else}}
<li class="build-duration"><abbr title="Not Applicable">N/A</abbr></li>
{{/if}}
{{/if}}

{{#if build.userId}}
<li class="build-user" title="User: {{build.userId}}">{{build.userId}}</li>
{{/if}}
</ul>
</div>
<div class="build-actions">
{{#unless project.disabled}}
<div class="status-bar" id="status-bar-{{id}}">
{{#if build.isBuilding}}
<div onclick="buildPipeline.fillDialog('${app.rootUrl}{{build.url}}console', 'Console output for {{project.name}} #{{build.number}}')">
<table class="progress-bar" align="center">
<tbody>
<tr title="Estimated remaining time: {{build.estimatedRemainingTime}}">
<td style="width: {{build.progress}}%" class="progress-bar-done" id="progress-bar-done{{id}}"></td>
<td style="width: {{build.progressLeft}}%" class="progress-bar-left" id="progress-bar-left{{id}}"></td>
</tr>
</tbody>
</table>
</div>
{{/if}}
</div>

<div class="icons" id="icons-{{id}}">
{{#if project.parameters.length}}
<j:set var="hasParameterIconUrl" value="${rootURL}/plugin/build-pipeline-plugin/images/has-parameter.png" />
<img title="This job has parameters" alt="This job has parameters" src="${hasParameterIconUrl}"/>
{{/if}}
{{#unless build.isPending}}
{{#unless build.isReadyToBeManuallyBuilt}}
<j:set var="consoleOutputIconUrl" value="${rootURL}/images/16x16/terminal.png" />
<j:choose>
<j:when test="${from.newWindowConsoleOutputLinkStyle}">
<a href="${rootURL}/{{build.url}}console" target="_blank">
<img title="console" alt="console" src="${consoleOutputIconUrl}" />
</a>
</j:when>
<j:when test="${from.thisWindowConsoleOutputLinkStyle}">
<a href="${rootURL}/{{build.url}}console">
<img title="console" alt="console" src="${consoleOutputIconUrl}" />
</a>
</j:when>
<j:otherwise>
<span onclick="buildPipeline.fillDialog('${app.rootUrl}{{build.url}}console', 'Console output for {{project.name}} #{{build.number}}')">
<img title="console" alt="console" src="${consoleOutputIconUrl}" />
</span>
</j:otherwise>
</j:choose>
{{/unless}}
{{/unless}}

{{#if build.isRerunnable}}
{{#if build.isSuccess}}
{{#if ${!from.triggerOnlyLatestJob}}}
<j:if test="${from.hasBuildPermission()}">
<span onclick="buildPipeline.showSpinner({{id}}); buildPipeline.rerunBuild({{id}}, '{{build.extId}}', [{{build.dependencyIds}}])">
<img title="re-run" alt="re-run" src="${rootURL}/images/16x16/redo.png" />
</span>
</j:if>
{{/if}}
{{else}}
{{#if ${from.triggerOnlyLatestJob}}}
{{#if build.isLatestBuild}}
{{#if build.isUpstreamBuildLatest}}
<span onclick="buildPipeline.showSpinner({{id}}); buildPipeline.rerunBuild({{id}}, '{{build.extId}}', [{{build.dependencyIds}}])">
<img title="retry" alt="retry" src="${rootURL}/images/16x16/redo.png" />
</span>
{{/if}}
{{/if}}
{{else}}
{{#if build.isManual}}
<span onclick="buildPipeline.showSpinner({{id}}); buildPipeline.triggerBuild({{id}}, '{{upstream.projectName}}', {{upstream.buildNumber}}, '{{project.name}}', [{{build.dependencyIds}}])">
<img title="retry" alt="retry" src="${rootURL}/images/16x16/clock.png" />
</span>
{{else}}
<span onclick="buildPipeline.showSpinner({{id}}); buildPipeline.rerunBuild({{id}}, '{{build.extId}}', [{{build.dependencyIds}}])">
<img title="retry" alt="retry" src="${rootURL}/images/16x16/redo.png" />
</span>
{{/if}}
{{/if}}
{{/if}}
{{/if}}

{{#if build.isReadyToBeManuallyBuilt}}
{{#if ${from.triggerOnlyLatestJob}}}
{{#if build.isUpstreamBuildLatestSuccess}}
<span onclick="buildPipeline.showSpinner({{id}}); buildPipeline.triggerBuild({{id}}, '{{upstream.projectName}}', {{upstream.buildNumber}}, '{{project.name}}', [{{build.dependencyIds}}])">
<img title="trigger" alt="trigger" src="${rootURL}/images/16x16/clock.png" />
</span>
{{/if}}
{{else}}
<span onclick="buildPipeline.showSpinner({{id}}); buildPipeline.triggerBuild({{id}}, '{{upstream.projectName}}', {{upstream.buildNumber}}, '{{project.name}}', [{{build.dependencyIds}}])">
<img title="trigger" alt="trigger" src="${rootURL}/images/16x16/clock.png" />
</span>
{{/if}}
{{/if}}
</div>
{{/unless}}
{{#if project.disabled}}
<div class="icons" id="icons-{{id}}">
<span class="disabled"><img src="${rootURL}/images/16x16/warning.png" atl="disabled" title="disabled" /></span>
</div>
{{/if}}
</div>
</div>
<st:include page="buildCardTemplate.jelly"
from="${from.getBuildCard()}"
it="${from}"/>
</script>

<script id="project-card-template" type="text/x-handlebars-template">
Expand All @@ -173,6 +35,11 @@
var projectCardTemplateSource = jQuery("#project-card-template").html();
var buildPipeline = new BuildPipeline(buildPipelineViewProxy, Handlebars.compile(buildCardTemplateSource), Handlebars.compile(projectCardTemplateSource), ${from.getRefreshFrequencyInMillis()});
</script>

<st:include page="buildCardHelpers.jelly"
from="${from.getBuildCard()}"
it="${from}"/>

<form method="post" action="gridBuilder/build" id="triggerPipelineForm" class="no-json"/>
<form method="post" name="pipelineViewForm" action="manualExecution" id="manualExecutionForm">

Expand Down Expand Up @@ -267,7 +134,6 @@
// generate build-card
var buildData = ${build.asJSON()};
jQuery("#build-${build.getId()}").append(buildPipeline.buildCardTemplate(buildData));

// add build proxy to proxies for future use
buildPipeline.buildProxies[${build.getId()}] = <st:bind value="${build}" />;
<j:if test="${build.getStatus() == 'BUILDING'}">
Expand Down
Expand Up @@ -11,6 +11,10 @@
</f:section>

<f:section title="Trigger Options">

<f:dropdownDescriptorSelector field="buildCard" title="${%Build Cards}"
descriptors="${descriptor.getBuildCardDescriptors()}"/>

<f:entry title="Restrict triggers to most recent successful builds" field="triggerOnlyLatestJob">
<f:booleanRadio default="true"/>
</f:entry>
Expand Down
@@ -0,0 +1,22 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<!--
This file is included once in the build pipeline file - it is intended to allow a BuildCardExtension to contribute
any 'global' scripts or assets to the build pipeline. This includes the ability to add a Handlebars helper
(if you really, really must be using JS in a handlebars template).
By default we just include helpers to append script tags to your build card
-->
<![CDATA[
<script type="text/javascript">
Handlebars.registerHelper('startScript', function() {
return new Handlebars.SafeString("<scr" + "ipt>");
});
Handlebars.registerHelper('endScript', function() {
return new Handlebars.SafeString("</scr" + "ipt>");
});
</script>
]]>
</j:jelly>

0 comments on commit 15b7b6a

Please sign in to comment.