Skip to content
Permalink
Browse files

[FIXED JENKINS-14591] add build card to filter out parameters

  • Loading branch information...
dalvizu committed Dec 8, 2016
1 parent 62192c7 commit d0221ecc8f3b8d84e2ac20d39e2595e23012f3a8
Showing with 423 additions and 126 deletions.
  1. +15 −15 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/BuildPipelineView.java
  2. +6 −3 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/DownstreamProjectGridBuilder.java
  3. +18 −11 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/ProjectForm.java
  4. +6 −8 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/BuildVariablesHeader.java
  5. +148 −0 ...ain/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/FilteredVariablesHeader.java
  6. +11 −13 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/NullColumnHeader.java
  7. +7 −7 ...main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/ParametersActionHeader.java
  8. +3 −35 ...ain/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/PipelineHeaderExtension.java
  9. +63 −0 ...u/com/centrumsystems/hudson/plugin/buildpipeline/extension/PipelineHeaderExtensionDescriptor.java
  10. +11 −13 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/SimpleColumnHeader.java
  11. +14 −15 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/SimpleRowHeader.java
  12. +1 −0 ...umsystems/hudson/plugin/buildpipeline/extension/AbstractNameValueHeader/projectCardTemplate.jelly
  13. +1 −1 ...ces/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/BuildVariablesHeader/config.jelly
  14. +31 −0 .../au/com/centrumsystems/hudson/plugin/buildpipeline/extension/FilteredVariablesHeader/config.jelly
  15. +8 −0 src/test/java/au/com/centrumsystems/hudson/plugin/buildpipeline/BuildPipelineViewTest.java
  16. +7 −5 src/test/java/au/com/centrumsystems/hudson/plugin/buildpipeline/ProjectFormTest.java
  17. +73 −0 ...java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/FilteredVariablesHeaderTest.java
@@ -27,6 +27,7 @@
import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.NullColumnHeader;
import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.PipelineHeaderExtension;
import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.BuildVariablesHeader;
import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.PipelineHeaderExtensionDescriptor;
import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.SimpleColumnHeader;
import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.SimpleRowHeader;
import com.google.common.base.Splitter;
@@ -203,6 +204,8 @@ public BuildPipelineView(final String name, final String buildViewTitle,
this.noOfDisplayedBuilds = noOfDisplayedBuilds;
this.triggerOnlyLatestJob = triggerOnlyLatestJob;
this.cssUrl = cssUrl;
this.rowHeaders = new NullColumnHeader();
this.columnHeaders = new SimpleRowHeader();
}

/**
@@ -766,28 +769,25 @@ public ListBoxModel doFillNoOfDisplayedBuildsItems() {
* @return
* a filtered and ordered list of descriptors matching the condition
*/
public List<Descriptor<PipelineHeaderExtension>> filter(Function<PipelineHeaderExtension, Boolean> condition) {
final List<Descriptor<PipelineHeaderExtension>> result = new ArrayList<Descriptor<PipelineHeaderExtension>>();
public List<PipelineHeaderExtensionDescriptor> filter(Function<PipelineHeaderExtensionDescriptor, Boolean> condition) {
final List<PipelineHeaderExtensionDescriptor> result = new ArrayList<PipelineHeaderExtensionDescriptor>();
final List<PipelineHeaderExtension> applicableExtensions = new ArrayList<PipelineHeaderExtension>();
for (PipelineHeaderExtension extension : PipelineHeaderExtension.all()) {
if (condition.apply(extension)) {
applicableExtensions.add(extension);
for (PipelineHeaderExtensionDescriptor descriptor : PipelineHeaderExtensionDescriptor.all()) {
if (condition.apply(descriptor)) {
result.add(descriptor);
}
}
Collections.sort(applicableExtensions);
for (PipelineHeaderExtension extension : applicableExtensions) {
result.add(extension.getDescriptor());
}
Collections.sort(result);
return result;
}

/**
* @return a list of PipelineHeaderExtension descriptors which can be used as a row header
*/
public List<Descriptor<PipelineHeaderExtension>> getRowHeaderDescriptors() {
return filter(new Function<PipelineHeaderExtension, Boolean>() {
public List<PipelineHeaderExtensionDescriptor> getRowHeaderDescriptors() {
return filter(new Function<PipelineHeaderExtensionDescriptor, Boolean>() {
@Override
public Boolean apply(PipelineHeaderExtension extension) {
public Boolean apply(PipelineHeaderExtensionDescriptor extension) {
return extension.appliesToRows();
}
});
@@ -796,11 +796,11 @@ public Boolean apply(PipelineHeaderExtension extension) {
/**
* @return a list of PipelineHeaderExtension descriptors which can be used as column headers
*/
public List<Descriptor<PipelineHeaderExtension>> getColumnHeaderDescriptors() {
return filter(new Function<PipelineHeaderExtension, Boolean>() {
public List<PipelineHeaderExtensionDescriptor> getColumnHeaderDescriptors() {
return filter(new Function<PipelineHeaderExtensionDescriptor, Boolean>() {

@Override
public Boolean apply(PipelineHeaderExtension extension) {
public Boolean apply(PipelineHeaderExtensionDescriptor extension) {
return extension.appliesToColumns();
}
});
@@ -1,5 +1,6 @@
package au.com.centrumsystems.hudson.plugin.buildpipeline;

import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.PipelineHeaderExtension;
import hudson.Extension;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
@@ -67,14 +68,16 @@ public DownstreamProjectGridBuilder(String firstJob) {
private final ItemGroup context;

/**
* @param columnHeaders
* column headers to get build parameters from
* @param context
* item group pipeline view belongs to, used to compute relative item names
* @param start The first project to lead the pipeline.
*/
private GridImpl(ItemGroup context, AbstractProject<?, ?> start) {
private GridImpl(PipelineHeaderExtension columnHeaders, ItemGroup context, AbstractProject<?, ?> start) {
this.context = context;
this.start = start;
placeProjectInGrid(0, 0, ProjectForm.as(start));
placeProjectInGrid(0, 0, ProjectForm.as(start, columnHeaders));
}

/**
@@ -224,7 +227,7 @@ public ProjectGrid build(BuildPipelineView owner) {
} else {
this.firstJobLink = "";
}
return new GridImpl(owner.getOwnerItemGroup(), getFirstJob(owner));
return new GridImpl(owner.getColumnHeaders(), owner.getOwnerItemGroup(), getFirstJob(owner));
}

@Override
@@ -1,6 +1,6 @@
package au.com.centrumsystems.hudson.plugin.buildpipeline;

import au.com.centrumsystems.hudson.plugin.util.BuildUtil;
import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.PipelineHeaderExtension;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
@@ -82,19 +82,24 @@ public ProjectForm(final String name) {

/**
* @param project
* project
* project\
* @param columnHeaders
* the column headers describing how to get build parameters
*/
public ProjectForm(final AbstractProject<?, ?> project) {
this(project, new LinkedHashSet<AbstractProject<?, ?>>(Arrays.asList(project)));
public ProjectForm(final AbstractProject<?, ?> project, final PipelineHeaderExtension columnHeaders) {
this(project, columnHeaders, new LinkedHashSet<AbstractProject<?, ?>>(Arrays.asList(project)));
}

/**
* @param project
* project
* @param columnHeaders
* column headers to get build parameters from
* @param parentPath
* already traversed projects
*/
private ProjectForm(final AbstractProject<?, ?> project, final Collection<AbstractProject<?, ?>> parentPath) {
private ProjectForm(final AbstractProject<?, ?> project, final PipelineHeaderExtension columnHeaders,
final Collection<AbstractProject<?, ?>> parentPath) {
final PipelineBuild pipelineBuild = new PipelineBuild(project.getLastBuild(), project, null);

name = pipelineBuild.getProject().getFullName();
@@ -105,7 +110,7 @@ private ProjectForm(final AbstractProject<?, ?> project, final Collection<Abstra
for (final AbstractProject<?, ?> dependency : project.getDownstreamProjects()) {
final Collection<AbstractProject<?, ?>> forkedPath = new LinkedHashSet<AbstractProject<?, ?>>(parentPath);
if (forkedPath.add(dependency)) {
dependencies.add(new ProjectForm(dependency, forkedPath));
dependencies.add(new ProjectForm(dependency, columnHeaders, forkedPath));
}
}
if (Hudson.getInstance().getPlugin("parameterized-trigger") != null) {
@@ -114,7 +119,7 @@ private ProjectForm(final AbstractProject<?, ?> project, final Collection<Abstra
for (final AbstractProject<?, ?> dependency : config.getProjectList(project.getParent(), null)) {
final Collection<AbstractProject<?, ?>> forkedPath = new LinkedHashSet<AbstractProject<?, ?>>(parentPath);
if (forkedPath.add(dependency)) {
final ProjectForm candidate = new ProjectForm(dependency, forkedPath);
final ProjectForm candidate = new ProjectForm(dependency, columnHeaders, forkedPath);
// if subprojects come back as downstreams someday, no duplicates wanted
if (!dependencies.contains(candidate)) {
dependencies.add(candidate);
@@ -128,7 +133,7 @@ private ProjectForm(final AbstractProject<?, ?> project, final Collection<Abstra

final AbstractBuild<?, ?> lastSuccessfulBuild = pipelineBuild.getProject().getLastSuccessfulBuild();
lastSuccessfulBuildNumber = (null == lastSuccessfulBuild) ? "" : "" + lastSuccessfulBuild.getNumber();
lastSuccessfulBuildParams = BuildUtil.getUnsensitiveParameters(lastSuccessfulBuild);
lastSuccessfulBuildParams = columnHeaders.getParameters(lastSuccessfulBuild);

this.project = project;
}
@@ -138,11 +143,13 @@ private ProjectForm(final AbstractProject<?, ?> project, final Collection<Abstra
*
* @param p
* project to be wrapped.
* @param columnHeaders
* column headers to grab build parameters from
* @return
* possibly null.
*/
public static ProjectForm as(AbstractProject<?, ?> p) {
return p != null ? new ProjectForm(p) : null;
public static ProjectForm as(AbstractProject<?, ?> p, PipelineHeaderExtension columnHeaders) {
return p != null ? new ProjectForm(p, columnHeaders) : null;
}

public String getName() {
@@ -243,7 +250,7 @@ public int getId() {
*/
@JavaScriptMethod
public String asJSON() {
return ProjectJSONBuilder.asJSON(new ProjectForm(project));
return ProjectJSONBuilder.asJSON(this);
}

}
@@ -26,7 +26,6 @@

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

import java.util.HashMap;
@@ -38,7 +37,6 @@
*
* @author dalvizu
*/
@Extension
public class BuildVariablesHeader extends AbstractNameValueHeader {

/**
@@ -59,25 +57,25 @@ public BuildVariablesHeader() {
if (retval.containsKey(paramName)) {
// We have the choice to hide the parameter or to replace it with special characters
retval.put(paramName, "********");
//retval.remove(paramName);
}
}
}

return retval;
}

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

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

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

@Override
public String getDisplayName() {
@@ -0,0 +1,148 @@
/***************************************************************************
* Copyright (C) 2014 Ping Identity Corporation
* All rights reserved.
* <p/>
* The contents of this file are the property of Ping Identity Corporation.
* You may not copy or use this file, in either source code or executable
* form, except in compliance with terms set by Ping Identity Corporation.
* For further information please contact:
* <p/>
* Ping Identity Corporation
* 1001 17th Street Suite 100
* Denver, CO 80202
* 303.468.2900
* http://www.pingidentity.com
**************************************************************************/
package au.com.centrumsystems.hudson.plugin.buildpipeline.extension;

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

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Specify which variables to show
* @author dalvizu
*/
public class FilteredVariablesHeader
extends AbstractNameValueHeader {

/**
* List of variables to show
*/
private List<FilteredVariable> filteredVariables;

/**
* Default constructor
* @param filteredVariables - from XML
*/
@DataBoundConstructor
public FilteredVariablesHeader(List<FilteredVariable> filteredVariables
) {

this.filteredVariables = filteredVariables;
}

@Override
public Map<String, String> getParameters(AbstractBuild<?, ?> build) {
final Map<String, String> returnValue = new HashMap<String, String>();
if (build != null) {

// only add variables if they are on the filteredVariables list
for (FilteredVariable variable : filteredVariables) {
if (build.getBuildVariables().containsKey(variable.variableName)) {
returnValue.put(variable.variableName, build.getBuildVariables().get(variable.variableName));
}
}

// obfuscate sensitive values
final Set<String> sensitiveBuildVariables = build.getSensitiveBuildVariables();
for (String paramName : sensitiveBuildVariables) {
if (returnValue.containsKey(paramName)) {
// We have the choice to hide the parameter or to replace it with special characters
returnValue.put(paramName, "********");
}
}
}

return returnValue;
}

public List<FilteredVariable> getFilteredVariables() {
return filteredVariables;
}

public void setFilteredVariables(List<FilteredVariable> filteredVariables) {
this.filteredVariables = filteredVariables;
}

/**
* UI placeholder for a string (yey)
*/
public static class FilteredVariable extends AbstractDescribableImpl<FilteredVariable> {

/**
* Default constructor
* @param variableName name of the variable
*/
@DataBoundConstructor
public FilteredVariable(String variableName) {
this.variableName = variableName;
}

/**
* Name of the variable
*/
private String variableName;

/**
* Get the name of the variable to show
* @return the name of the variable
*/
public String getVariableName() {
return variableName;
}

/**
* Set the name of the variable
* @param variableName the name of the variable
*/
public void setVariableName(String variableName) {
this.variableName = variableName;
}

/**
* Descriptor class, since we're in the UI
*/
@Extension
public static class DescriptorImpl extends Descriptor<FilteredVariable> {
public String getDisplayName() {
return "";
}
}
}

/**
* Descriptor, since we show it in UI
*/
@Extension
public static class DescriptorImpl
extends PipelineHeaderExtensionDescriptor {

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

@Override
public String getDisplayName() {
return "Specify which build variables";
}
}
}
Oops, something went wrong.

0 comments on commit d0221ec

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.