Skip to content
Permalink
Browse files
Implemented JENKINS-37331 - Add branches to build list view column
  • Loading branch information
MadsNielsen committed Apr 19, 2017
1 parent 44da1a4 commit 8ccee7784afd295c6fb64c59af8d64fa8506e034
Showing 2 changed files with 65 additions and 0 deletions.
@@ -0,0 +1,56 @@
package hudson.plugins.git;

import hudson.views.ListViewColumn;
import hudson.Extension;
import hudson.model.Item;
import hudson.scm.SCM;
import hudson.views.ListViewColumnDescriptor;
import java.util.ArrayList;
import jenkins.triggers.SCMTriggerItem;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Class that adds an optional 'Git branches to build' column to a list view.
*
* @author Mads
*/
public class GitBranchSpecifierColumn extends ListViewColumn {

@DataBoundConstructor
public GitBranchSpecifierColumn() { }

public String getBranchSpecifier( final Item item ) {
String branchSpec = "";
SCMTriggerItem s = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(item);
if(s != null) {
for(SCM scm : s.getSCMs()) {
if (scm instanceof GitSCM) {
GitSCM gitScm = (GitSCM)scm;
ArrayList<String> branches = new ArrayList<String>();
for(BranchSpec spec : gitScm.getBranches()) {
branches.add(spec.getName());
}
branchSpec = StringUtils.join(branches, " ");
}
}
}
return branchSpec;
}

@Extension
public static class DescriptorImpl extends ListViewColumnDescriptor {

@Override
public String getDisplayName() {
return "Git branches to build";
}

@Override
public boolean shownByDefault() {
return false;
}

}

}
@@ -0,0 +1,9 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core">
<j:set var="branchSpec" value="${it.getBranchSpecifier(job)}"/>
<td data="${branchSpec}">
<j:forEach items="${branchSpec.split(' ')}" var="i">
<p>${i}</p>
</j:forEach>
</td>
</j:jelly>

0 comments on commit 8ccee77

Please sign in to comment.