Skip to content

Commit 76981eb

Browse files
committed
replacing old automate report with new Cad reports
1 parent 5091706 commit 76981eb

File tree

7 files changed

+52
-15
lines changed

7 files changed

+52
-15
lines changed

src/main/java/com/browserstack/automate/ci/common/constants/Constants.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ public class Constants {
1919
public static final String BROWSERSTACK_CONFIG_DETAILS_ENDPOINT = "/v1/builds/buildReport";
2020

2121
public static final String INTEGRATIONS_TOOL_KEY = "jenkins";
22-
public static final String REPORT_FORMAT = "richHtml";
2322

2423
public static final String BROWSERSTACK_TEST_REPORT_URL = "testReportBrowserStack";
25-
public static final String BROWSERSTACK_CAD_REPORT_DISPLAY_NAME = "BrowserStack Build Test Reports";
24+
public static final String BROWSERSTACK_CAD_REPORT_DISPLAY_NAME = "BrowserStack Test Report and Insights";
25+
public static final String BROWSERSTACK_REPORT_FILENAME = "browserstack-report";
26+
public static final String BROWSERSTACK_REPORT_FOLDER = "browserstack-artifacts";
27+
28+
public static final String BROWSERSTACK_REPORT_AUT_PIPELINE_FUNCTION = "browserStackReportAut";
2629

2730
// Product
2831
public static final String AUTOMATE = "automate";

src/main/java/com/browserstack/automate/ci/jenkins/integrationService/BrowserStackTestReportAction.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
import com.browserstack.automate.ci.common.constants.Constants;
44
import com.browserstack.automate.ci.jenkins.BrowserStackCredentials;
55
import com.google.gson.Gson;
6+
import hudson.EnvVars;
7+
import hudson.FilePath;
68
import hudson.model.Action;
79
import hudson.model.Run;
10+
import hudson.model.TaskListener;
11+
import hudson.tasks.ArtifactArchiver;
812
import org.json.JSONObject;
913
import okhttp3.*;
1014

15+
import java.io.IOException;
1116
import java.io.PrintStream;
1217
import java.util.Arrays;
1318
import java.util.HashMap;
@@ -93,7 +98,7 @@ private Map<String, Object> createReportParams() {
9398
params.put("buildStartedAt", buildCreatedAt);
9499
params.put("originalBuildName", buildName);
95100
params.put("requestingCi", Constants.INTEGRATIONS_TOOL_KEY);
96-
params.put("reportFormat", Arrays.asList(Constants.REPORT_FORMAT));
101+
params.put("reportFormat", Arrays.asList("richHtml", "basicHtml"));
97102
params.put("requestType", RquestTypeForJenkins);
98103
params.put("userTimeout", DEFAULT_REPORT_TIMEOUT);
99104
return params;
@@ -148,6 +153,33 @@ private void setReportSuccess(JSONObject report) {
148153
reportStatus = SUCCESS_REPORT;
149154
reportHtml = report != null ? report.optString("richHtml", defaultHTML) : defaultHTML;
150155
reportStyle = report != null ? report.optString("richCss", "") : "";
156+
157+
try {
158+
String basicHtml = report != null ? report.optString("basicHtml", defaultHTML) : defaultHTML;
159+
String fullHtml = "<!DOCTYPE html> <html><head> <head>" + basicHtml + "</html>";
160+
161+
// Save the HTML content to a file in the workspace
162+
FilePath workspace = new FilePath(run.getRootDir()).getParent();
163+
ArtifactArchiver artifactArchiver = getArtifactArchiver(workspace, fullHtml);
164+
artifactArchiver.perform(run, workspace, new EnvVars(), null, TaskListener.NULL);
165+
} catch (Exception e) {
166+
logError(logger, "Failed to save or archive report artifact: " + e.getMessage());
167+
}
168+
}
169+
170+
private static ArtifactArchiver getArtifactArchiver(FilePath workspace, String fullHtml) throws IOException, InterruptedException {
171+
FilePath artifactsDir = new FilePath(workspace, Constants.BROWSERSTACK_REPORT_FOLDER);
172+
artifactsDir.mkdirs();
173+
String htmlFileName = Constants.BROWSERSTACK_REPORT_FILENAME + ".html";
174+
175+
FilePath htmlFile = new FilePath(artifactsDir, htmlFileName);
176+
177+
htmlFile.write(fullHtml, "UTF-8");
178+
String artifactFilePath = Constants.BROWSERSTACK_REPORT_FOLDER + "/" + htmlFileName;
179+
// Archive the file as an artifact
180+
ArtifactArchiver artifactArchiver = new ArtifactArchiver(artifactFilePath);
181+
artifactArchiver.setAllowEmptyArchive(false);
182+
return artifactArchiver;
151183
}
152184

153185
private void handleFetchException(Exception e) {
@@ -202,7 +234,7 @@ public String getIconFileName() {
202234

203235
@Override
204236
public String getDisplayName() {
205-
return Constants.BROWSERSTACK_CAD_REPORT_DISPLAY_NAME;
237+
return Constants.BROWSERSTACK_REPORT_DISPLAY_NAME;
206238
}
207239

208240
@Override

src/main/java/com/browserstack/automate/ci/jenkins/integrationService/BrowserStackTestReportPublisher.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
import org.jenkinsci.Symbol;
2121
import org.kohsuke.stapler.DataBoundConstructor;
2222

23+
import javax.annotation.CheckForNull;
2324
import java.io.IOException;
2425
import java.io.PrintStream;
25-
import java.net.URLEncoder;
26-
import java.text.SimpleDateFormat;
2726
import java.util.*;
2827
import java.util.concurrent.ConcurrentHashMap;
2928
import java.util.logging.Logger;
@@ -33,11 +32,11 @@
3332

3433
public class BrowserStackTestReportPublisher extends Recorder implements SimpleBuildStep {
3534
private static final Logger LOGGER = Logger.getLogger(BrowserStackTestReportPublisher.class.getName());
36-
private final Map<String, String> customEnvVars;
35+
private Map<String, String> customEnvVars;
3736

3837
@DataBoundConstructor
39-
public BrowserStackTestReportPublisher(Map<String, String> customEnvVars) {
40-
this.customEnvVars = customEnvVars != null && !customEnvVars.isEmpty() ? new ConcurrentHashMap<>(customEnvVars) : new ConcurrentHashMap<>();
38+
public BrowserStackTestReportPublisher(@CheckForNull String product) {
39+
this.customEnvVars = new ConcurrentHashMap<>();
4140
}
4241

4342
@Override
@@ -83,7 +82,7 @@ public BuildStepMonitor getRequiredMonitorService() {
8382
return BuildStepMonitor.NONE;
8483
}
8584

86-
@Symbol("browserStackBuildTestReports")
85+
@Symbol(Constants.BROWSERSTACK_REPORT_PIPELINE_FUNCTION)
8786
@Extension
8887
public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> {
8988

@@ -93,7 +92,6 @@ public boolean isApplicable(Class<? extends AbstractProject> aClass) {
9392
// indicates that this builder can be used with all kinds of project types
9493
return true;
9594
}
96-
9795
@Override
9896
public String getDisplayName() {
9997
return Constants.BROWSERSTACK_CAD_REPORT_DISPLAY_NAME;

src/main/java/com/browserstack/automate/ci/jenkins/pipeline/BrowserStackReportStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Set<? extends Class<?>> getRequiredContext() {
4747

4848
@Override
4949
public String getFunctionName() {
50-
return Constants.BROWSERSTACK_REPORT_PIPELINE_FUNCTION;
50+
return Constants.BROWSERSTACK_REPORT_AUT_PIPELINE_FUNCTION ; // deprecated Constants.BROWSERSTACK_REPORT_PIPELINE_FUNCTION;
5151
}
5252

5353
@Override
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:l="/lib/layout">
3-
This step will generate BrowserStack Cypress Test Report by utilising the build name from the environment variable BROWSERSTACK_BUILD_NAME set by the BrowserStack plugin
3+
This step will generate BrowserStack Cypress Test Report by utilising the build name from the environment variable BROWSERSTACK_BUILD_NAME set by the BrowserStack plugin.
4+
<br/>
5+
⚠️ Note: This post-build action is deprecated and will no longer be supported in future releases. To continue generating test reports, please use the new BrowserStack Test Report and Insights post-build action.
46
</j:jelly>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:l="/lib/layout">
3-
This step will generate BrowserStack Test Report by utilising the build name from the environment variable BROWSERSTACK_BUILD_NAME set by the BrowserStack plugin
3+
This step will generate BrowserStack Test Report by utilising the build name from the environment variable BROWSERSTACK_BUILD_NAME set by the BrowserStack plugin.
4+
<br/>
5+
⚠️ Note: This post-build action is deprecated and will no longer be supported in future releases. To continue generating test reports, please use the new BrowserStack Test Report and Insights post-build action.
46
</j:jelly>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:l="/lib/layout">
3-
This step will generate BrowserStack Test Report by utilising the build name from the environment variable BROWSERSTACK_BUILD_NAME set by the BrowserStack plugin
3+
This step will generate BrowserStack Test Report and Insights by using the build name from the environment variable BROWSERSTACK_BUILD_NAME set by the BrowserStack plugin
44
</j:jelly>

0 commit comments

Comments
 (0)