-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathBrowserStackReportPublisher.java
More file actions
93 lines (74 loc) · 3.75 KB
/
Copy pathBrowserStackReportPublisher.java
File metadata and controls
93 lines (74 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.browserstack.automate.ci.jenkins;
import com.browserstack.automate.ci.common.BrowserStackEnvVars;
import com.browserstack.automate.ci.common.constants.Constants;
import com.browserstack.automate.ci.common.enums.ProjectType;
//import com.browserstack.automate.ci.common.tracking.PluginsTracker;
import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.AbstractProject;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;
import jenkins.tasks.SimpleBuildStep;
import org.kohsuke.stapler.DataBoundConstructor;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Optional;
import static com.browserstack.automate.ci.common.logger.PluginLogger.log;
public class BrowserStackReportPublisher extends Recorder implements SimpleBuildStep {
@DataBoundConstructor
public BrowserStackReportPublisher() {
}
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
}
@Override
public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException {
final PrintStream logger = listener.getLogger();
// final PluginsTracker tracker = new PluginsTracker();
final boolean pipelineStatus = false;
log(logger, "Generating BrowserStack Test Report");
final EnvVars parentEnvs = build.getEnvironment(listener);
String browserStackBuildName = parentEnvs.get(BrowserStackEnvVars.BROWSERSTACK_BUILD_NAME);
final String browserStackAppID = parentEnvs.get(BrowserStackEnvVars.BROWSERSTACK_APP_ID);
browserStackBuildName = Optional.ofNullable(browserStackBuildName).orElse(parentEnvs.get(Constants.JENKINS_BUILD_TAG));
ProjectType product = ProjectType.AUTOMATE;
if (browserStackAppID != null && !browserStackAppID.isEmpty()) {
product = ProjectType.APP_AUTOMATE;
}
// tracker.reportGenerationInitialized(browserStackBuildName, product.name(), pipelineStatus);
log(logger, "BrowserStack Project identified as : " + product.name());
// final BrowserStackReportForBuild bstackReportAction =
// new BrowserStackReportForBuild(build, product, browserStackBuildName, logger, tracker, pipelineStatus, null);
final BrowserStackReportForBuild bstackReportAction =
new BrowserStackReportForBuild(build, product, browserStackBuildName, logger, pipelineStatus, null);
final boolean reportResult = bstackReportAction.generateBrowserStackReport();
build.addAction(bstackReportAction);
String reportStatus = reportResult ? Constants.ReportStatus.SUCCESS : Constants.ReportStatus.FAILED;
log(logger, "BrowserStack Report Status: " + reportStatus);
// tracker.reportGenerationCompleted(reportStatus, product.name(), pipelineStatus,
// browserStackBuildName, bstackReportAction.getBrowserStackBuildID());
}
@Extension
public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> {
@Override
@SuppressWarnings("rawtypes")
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
// indicates that this builder can be used with all kinds of project types
return true;
}
/**
* This human readable name is used in the configuration screen.
*/
@Override
public String getDisplayName() {
return Constants.BROWSERSTACK_REPORT_DISPLAY_NAME;
}
}
}