Skip to content

Commit

Permalink
Make parameters for publish sauce labs test results pipeline step opt…
Browse files Browse the repository at this point in the history
…ional - JENKINS-37610

Also make a helper symbol of saucePublisher()
  • Loading branch information
Gavin Mogan committed Jan 27, 2017
1 parent 18608f6 commit cc61f90
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -265,6 +265,12 @@
<artifactId>findbugs-annotations</artifactId>
<version>1.3.9-1</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>symbol-annotation</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
Expand Down
Expand Up @@ -17,12 +17,15 @@
import hudson.util.DescribableList;
import jenkins.tasks.SimpleBuildStep;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.StaplerRequest;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand All @@ -35,9 +38,13 @@
* @see <a href="https://issues.jenkins-ci.org/browse/JENKINS-11721">JENKINS-11721</a>
*/
public class SauceOnDemandTestPublisher extends Recorder implements SimpleBuildStep {
private final DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers;
private DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers = new DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>>(Saveable.NOOP);;

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

public SauceOnDemandTestPublisher(DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers) {
super();
this.testDataPublishers = testDataPublishers;
Expand Down Expand Up @@ -137,11 +144,26 @@ protected SauceOnDemandReportPublisher createReportPublisher() {
return new SauceOnDemandReportPublisher();
}

public DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> getTestDataPublishers() {
return testDataPublishers;
public List<TestDataPublisher> getTestDataPublishers() {
return testDataPublishers == null ? Collections.<TestDataPublisher>emptyList() : testDataPublishers;
}

/*@DataBoundSetter
public void setTestDataPublishers(ArrayList testDataPublishers) {
// This should never actually be called, but is needed because the pipeline generator provides a list
this.testDataPublishers = new DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>>(
Saveable.NOOP,
testDataPublishers
);
}*/

@DataBoundSetter public final void setTestDataPublishers(@Nonnull List<TestDataPublisher> testDataPublishers) {
this.testDataPublishers = new DescribableList<TestDataPublisher,Descriptor<TestDataPublisher>>(Saveable.NOOP);
this.testDataPublishers.addAll(testDataPublishers);
}

@Extension
@Symbol("saucePublisher")
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {

@Override
Expand All @@ -153,17 +175,5 @@ public String getDisplayName() {
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return !TestDataPublisher.all().isEmpty();
}

@Override
public Publisher newInstance(StaplerRequest req, JSONObject formData) throws Descriptor.FormException {
DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers =
new DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>>(Saveable.NOOP);
try {
testDataPublishers.rebuild(req, formData, TestDataPublisher.all());
} catch (IOException e) {
throw new Descriptor.FormException(e, null);
}
return new SauceOnDemandTestPublisher(testDataPublishers);
}
}
}
@@ -0,0 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core">

</j:jelly>
@@ -0,0 +1,5 @@
<div>
This step will trigger jenkins to parse the output of your build for <code>SauceOnDemandSessionID</code> lines and will attempt to update the job on sauce labs with the proper status.

See <a href="https://wiki.saucelabs.com/display/DOCS/Setting+Up+Reporting+between+Sauce+Labs+and+Jenkins">the Sauce Labs wiki</a> for more information
</div>

0 comments on commit cc61f90

Please sign in to comment.