Skip to content

Commit

Permalink
JENKINS-3549: display promotion stars on the view.
Browse files Browse the repository at this point in the history
see also pull request #30 which is an alternative implementation.
however instead of considering only the last build, consider all promotion
processes; those may point to different builds.
  • Loading branch information
dnozay committed Jul 6, 2015
1 parent afd01b6 commit a505215
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 0 deletions.
Expand Up @@ -58,6 +58,22 @@ public AbstractBuild<?,?> getLatest(PromotionProcess p) {
return list.size() > 0 ? list.get(0) : null;
}

public List<PromotionProcess> getPromotionProcesses() {
List<PromotionProcess> processes = null;
processes = getProcesses();
if (processes == null) {
processes = new ArrayList<PromotionProcess>();
}
return processes;
}

public Status getStatus(PromotionProcess process) {
List<Promotion> list = getPromotions( process );
Promotion latest = list.size() > 0 ? list.get(0) : null;
Status status = latest != null ? latest.getStatus() : null;
return status;
}

/**
* Finds the last promoted build under the given criteria.
*/
Expand Down
@@ -0,0 +1,42 @@
package hudson.plugins.promoted_builds;

import org.kohsuke.stapler.DataBoundConstructor;

import hudson.Extension;
import hudson.model.Job;
import hudson.model.Run;
import hudson.views.ListViewColumn;
import hudson.views.ListViewColumnDescriptor;

import java.util.ArrayList;
import java.util.List;

public class PromotionStatusColumn extends ListViewColumn {

@DataBoundConstructor
public PromotionStatusColumn() {
super();
}

public PromotedProjectAction getAction(Job job) {
PromotedProjectAction action = job.getAction(PromotedProjectAction.class);
return action;
}

@Extension
public static class DescriptorImpl extends ListViewColumnDescriptor {

public DescriptorImpl() {
}

@Override
public String getDisplayName() {
return Messages.PromotionStatusColumn_DisplayName();
}

public boolean shownByDefault() {
return false;
}
}

}
6 changes: 6 additions & 0 deletions src/main/java/hudson/plugins/promoted_builds/Status.java
Expand Up @@ -271,6 +271,12 @@ public Promotion getLast() {
return null;
}

public Boolean isLastAnError() {
Promotion l = getLast();
return (l != null && l.getResult() != Result.SUCCESS);
}


/**
* Gets all the promotion builds.
*/
Expand Down
Expand Up @@ -36,3 +36,4 @@ Promotion.PromotePermission.Description=This permission allows user to use force
Promotion.RunnerImpl.Promoting = Promoting {0}
Promotion.RunnerImpl.SchedulingBuild = scheduling build for {0}
PromotionCause.ShortDescription = Started by promotion {0} for project "{1}", build number {2}
PromotionStatusColumn.DisplayName = Promotions
@@ -0,0 +1,47 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout">
<td>
<j:set var="ppa" value="${it.getAction(job)}"/>
<j:choose>
<j:when test="${ppa!=null}">
<j:set var="pp" value="${ppa.getPromotionProcesses()}"/>
<j:choose>
<j:when test="${pp!=null}">
<j:forEach var="process" items="${pp}">
<j:set var="status" value="${ppa.getStatus(process)}"/>
<j:set var="icon" value="${process.getIcon()}"/>
<j:set var="iconUrl" value="${resURL}/plugin/promoted-builds/icons/${iconSize}/${icon}.png"/>
<img width="${iconSize}" height="${iconSize}"
title="${%PromotionProcess} ${process.name}"
src="${iconUrl}"/>
<j:choose>
<j:when test="${status!=null}">
<j:if test="${status.isLastAnError()}">
<j:set var="iconUrl" value="${resURL}/images/${iconSize}/error.png"/>
<img width="${iconSize}" height="${iconSize}"
title="${%PromotionProcess} ${process.name} ${%PromotionProcess.failed}"
src="${iconUrl}"/>
</j:if>
<j:set var="target" value="${status.getTarget()}"/>
<a href="${jobBaseUrl}${job.shortUrl}${target.number}/" class="model-link inside">
${target.displayName}
</a>
</j:when>
<j:otherwise><!-- promotion has never happened / no builds -->
${%Otherwise.noBuild}
</j:otherwise>
</j:choose>
</j:forEach>
</j:when>
<j:otherwise><!-- job has no promotion process (despite project action) -->
${%Otherwise.noPromotionProcess}
</j:otherwise>
</j:choose>
</j:when>
<j:otherwise><!-- job has no promotion process (no project action) -->
${%Otherwise.noPromotedProjectAction}
</j:otherwise>
</j:choose>
</td>
</j:jelly>

@@ -0,0 +1,5 @@
PromotionProcess = Promotion process
PromotionProcess.failed = failed
Otherwise.noBuild = N/A
Otherwise.noPromotionProcess = N/A
Otherwise.noPromotedProjectAction = N/A
@@ -0,0 +1,6 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core">
<th>
${%PromotionStatusColumn.Header}
</th>
</j:jelly>
@@ -0,0 +1 @@
PromotionStatusColumn.Header = Promotions
@@ -0,0 +1,8 @@
<?jelly escape-by-default='true'?>
<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" xmlns:p="/lib/hudson/project">
<f:block>
<p>${%PromotionStatusColumn.Blurb}</p>
</f:block>
</j:jelly>
@@ -0,0 +1 @@
PromotionStatusColumn.Blurb = This column shows the promotion status of the last build.

0 comments on commit a505215

Please sign in to comment.