Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

JobPropertyStep #209

Merged
merged 14 commits into from
Oct 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import hudson.search.SearchIndexBuilder;
import hudson.security.ACL;
import hudson.slaves.WorkspaceList;
import hudson.tasks.LogRotator;
import hudson.triggers.SCMTrigger;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
Expand All @@ -73,6 +74,7 @@
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.servlet.ServletException;
import jenkins.model.BuildDiscarder;
import jenkins.model.Jenkins;
import jenkins.model.ParameterizedJobMixIn;
import jenkins.model.lazy.LazyBuildMixIn;
Expand All @@ -81,6 +83,7 @@
import net.sf.json.JSONObject;
import org.acegisecurity.Authentication;
import org.jenkinsci.plugins.workflow.flow.FlowDefinition;
import org.jenkinsci.plugins.workflow.job.properties.BuildDiscarderProperty;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -521,6 +524,29 @@ public void addTrigger(Trigger trigger) {
// TODO call SCM.processWorkspaceBeforeDeletion
}

/** Actually it does, but we want to suppress this section of {@code Job/configure.jelly} in favor of {@link BuildDiscarderProperty}. */
@Override public boolean supportsLogRotator() {
return false;
}

@SuppressWarnings("deprecation")
@Override public LogRotator getLogRotator() {
BuildDiscarder buildDiscarder = getBuildDiscarder();
return buildDiscarder instanceof LogRotator ? (LogRotator) buildDiscarder : null;
}

@Override public void setBuildDiscarder(BuildDiscarder bd) throws IOException {
removeProperty(BuildDiscarderProperty.class);
if (bd != null) {
addProperty(new BuildDiscarderProperty(bd));
}
}

@Override public BuildDiscarder getBuildDiscarder() {
BuildDiscarderProperty prop = getProperty(BuildDiscarderProperty.class);
return prop != null ? prop.getStrategy() : /* settings compatibility */ super.getBuildDiscarder();
}

@Initializer(before=InitMilestone.EXTENSIONS_AUGMENTED)
public static void alias() {
Items.XSTREAM2.alias("flow-definition", WorkflowJob.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,35 @@
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.workflow.multibranch;
package org.jenkinsci.plugins.workflow.job.properties;

import hudson.Extension;
import hudson.model.Job;
import hudson.model.Run;
import jenkins.branch.BranchPropertyDescriptor;
import jenkins.branch.MultiBranchProjectDescriptor;
import jenkins.branch.ParameterDefinitionBranchProperty;
import jenkins.model.BuildDiscarder;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.kohsuke.stapler.DataBoundConstructor;

public class WorkflowParameterDefinitionBranchProperty extends ParameterDefinitionBranchProperty {
/**
* Defines a {@link BuildDiscarder}.
* TODO consider whether this should be moved upstream to core.
*/
public class BuildDiscarderProperty extends OptionalJobProperty<WorkflowJob> {

private final BuildDiscarder strategy;

@DataBoundConstructor public WorkflowParameterDefinitionBranchProperty() {}
@DataBoundConstructor public BuildDiscarderProperty(BuildDiscarder strategy) {
this.strategy = strategy;
}

@Override protected <P extends Job<P, B>, B extends Run<P, B>> boolean isApplicable(Class<P> clazz) {
return clazz == WorkflowJob.class;
public BuildDiscarder getStrategy() {
return strategy;
}

@Extension public static class DescriptorImpl extends BranchPropertyDescriptor {
@Extension public static class DescriptorImpl extends OptionalJobPropertyDescriptor {

@Override protected boolean isApplicable(MultiBranchProjectDescriptor projectDescriptor) {
return WorkflowMultiBranchProject.class.isAssignableFrom(projectDescriptor.getClazz());
@Override public String getDisplayName() {
return "Discard Old Builds";
}

@Override
public String getDisplayName() {
return "Parameters";
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* The MIT License
*
* Copyright 2015 CloudBees, Inc.
*
* 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 org.jenkinsci.plugins.workflow.job.properties;

import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor;
import hudson.model.ParametersDefinitionProperty;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;

/**
* Job property which may or may not be present.
* Must define {@code config-details.jelly} or {@code config-details.groovy}.
* TODO should be moved into core and implemented by {@link ParametersDefinitionProperty}.
*/
abstract class OptionalJobProperty<J extends Job<?,?>> extends JobProperty<J> {

@Override
public OptionalJobPropertyDescriptor getDescriptor() {
return (OptionalJobPropertyDescriptor) super.getDescriptor();
}

public static abstract class OptionalJobPropertyDescriptor extends JobPropertyDescriptor {

protected OptionalJobPropertyDescriptor(Class<? extends JobProperty<?>> clazz) {
super(clazz);
}

protected OptionalJobPropertyDescriptor() {}

@Override
public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return formData.optBoolean("specified") ? super.newInstance(req, formData) : null;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License

Copyright 2015 CloudBees, Inc.

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.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:dropdownDescriptorSelector field="strategy" title="${%Strategy}"/>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div>
This controls the disk consumption of Jenkins by managing how long you'd like to keep
records of the builds (such as console output, build artifacts, and so on.)
Jenkins offers two criteria:

<ol>
<li>
Driven by age. You can have Jenkins delete a record if it reaches a certain age
(for example, 7 days old.)
<li>
Driven by number. You can have Jenkins make sure that it only maintains up to
N build records. If a new build is started, the oldest record will
be simply removed.
</ol>

Jenkins also allows you to mark an individual build as 'Keep this log forever', to
exclude certain important builds from being discarded automatically.
The last stable and last successful build are always kept as well.
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License

Copyright 2015 CloudBees, Inc.

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.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form">
<f:block>
<f:optionalBlock title="${descriptor.displayName}" name="specified" checked="${instance != null}" inline="true">
<st:include page="config-details" from="${descriptor}" class="${descriptor.clazz}"/>
</f:optionalBlock>
</f:block>
</j:jelly>
11 changes: 9 additions & 2 deletions multibranch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ THE SOFTWARE.
<parent>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-pom</artifactId>
<version>1.11-beta-1</version>
<version>1.11-SNAPSHOT</version>
</parent>
<version>1.11-beta-2-SNAPSHOT</version> <!-- TODO cannot release a non-beta until branch-api dep is out of beta -->
<properties>
Expand Down Expand Up @@ -58,14 +58,21 @@ THE SOFTWARE.
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>branch-api</artifactId>
<version>0.2-beta-5</version>
<version>0.2-beta-6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-aggregator</artifactId>
<version>${workflow.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-support</artifactId>
Expand Down
Loading