Skip to content

Commit 7ec7273

Browse files
authored
Merge branch 'master' into INTG_1575_JENKINS_REPORT
2 parents 162fd1e + 914b236 commit 7ec7273

File tree

8 files changed

+153
-47
lines changed

8 files changed

+153
-47
lines changed

src/main/java/com/browserstack/automate/ci/common/BrowserStackBuildWrapperOperations.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ public void buildEnvVars(Map<String, String> env) {
186186
env.put(BrowserStackEnvVars.BROWSERSTACK_RERUN, reRun);
187187
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_RERUN, reRun);
188188
}
189+
190+
String host = env.get(BrowserStackEnvVars.QEI_URL);
191+
if ( host != null ) {
192+
logEnvVar(BrowserStackEnvVars.QEI_URL, host);
193+
Constants.QualityDashboardAPI.setHost(host);
194+
} else {
195+
Constants.QualityDashboardAPI.setHost(Constants.QualityDashboardAPI.QEI_DEFAULT_URL);
196+
}
189197
}
190198

191199
public void logEnvVar(String key, String value) {

src/main/java/com/browserstack/automate/ci/common/BrowserStackEnvVars.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ public interface BrowserStackEnvVars {
1717
String GRR_JENKINS_KEY = "BROWSERSTACK_GRR_REGION";
1818
String AUTOMATE_API_ENV_KEY = "browserstack.automate.api";
1919
String APP_AUTOMATE_API_ENV_KEY = "browserstack.app-automate.api";
20+
String QEI_URL = "QEI_URL";
2021
}

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

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,71 @@ public static final class SessionStatus {
7575
}
7676

7777
public static final class QualityDashboardAPI {
78-
public static final String URL_BASE = "https://quality-engineering-insights.browserstack.com/api/v1/jenkins";
79-
80-
public static final String LOG_MESSAGE = URL_BASE + "/log-message";
81-
public static final String IS_INIT_SETUP_REQUIRED = URL_BASE + "/init-setup-required";
82-
83-
public static final String HISTORY_FOR_DAYS = URL_BASE + "/history-for-days";
84-
85-
public static final String SAVE_PIPELINES = URL_BASE + "/save-pipelines";
86-
87-
public static final String SAVE_PIPELINE_RESULTS = URL_BASE + "/save-pipeline-results";
88-
89-
public static final String ITEM_CRUD = URL_BASE + "/item";
90-
public static final String IS_QD_ENABLED = URL_BASE + "/qd-enabled";
91-
public static final String IS_PIPELINE_ENABLED = URL_BASE + "/pipeline-enabled";
92-
public static final String GET_RESULT_DIRECTORY = URL_BASE + "/get-result-directory";
93-
94-
public static final String UPLOAD_RESULT_ZIP = URL_BASE + "/upload-result";
95-
public static final String STORE_PIPELINE_RESULTS = URL_BASE + "/save-results";
96-
97-
public static final String PROJECTS_PAGE_SIZE = URL_BASE + "/projects-page-size";
98-
public static final String RESULTS_PAGE_SIZE = URL_BASE + "/results-page-size";
78+
public static final String QEI_DEFAULT_URL = "https://quality-engineering-insights.browserstack.com";
79+
public static String host = QEI_DEFAULT_URL;
80+
81+
public static String getHost() {
82+
return host;
83+
}
84+
85+
public static void setHost(String newHost) {
86+
host = newHost;
87+
}
88+
89+
public static final String getURLBase() {
90+
return getHost() + "/api/v1/jenkins";
91+
}
92+
93+
public static final String getLogMessageEndpoint() {
94+
return getURLBase() + "/log-message";
95+
}
96+
97+
public static final String getIsInitSetupRequiredEndpoint() {
98+
return getURLBase() + "/init-setup-required";
99+
}
100+
101+
public static final String getHistoryForDaysEndpoint() {
102+
return getURLBase() + "/history-for-days";
103+
}
104+
105+
public static final String getSavePipelinesEndpoint() {
106+
return getURLBase() + "/save-pipelines";
107+
}
108+
109+
public static final String getSavePipelineResultsEndpoint() {
110+
return getURLBase() + "/save-pipeline-results";
111+
}
112+
113+
public static final String getItemCrudEndpoint() {
114+
return getURLBase() + "/item";
115+
}
116+
117+
public static final String getIsQdEnabledEndpoint() {
118+
return getURLBase() + "/qd-enabled";
119+
}
120+
121+
public static final String getIsPipelineEnabledEndpoint() {
122+
return getURLBase() + "/pipeline-enabled";
123+
}
124+
125+
public static final String getResultDirectoryEndpoint() {
126+
return getURLBase() + "/get-result-directory";
127+
}
128+
129+
public static final String getUploadResultZipEndpoint() {
130+
return getURLBase() + "/upload-result";
131+
}
132+
133+
public static final String getStorePipelineResultsEndpoint() {
134+
return getURLBase() + "/save-results";
135+
}
136+
137+
public static final String getProjectsPageSizeEndpoint() {
138+
return getURLBase() + "/projects-page-size";
139+
}
140+
141+
public static final String getResultsPageSizeEndpoint() {
142+
return getURLBase() + "/results-page-size";
143+
}
99144
}
100145
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public boolean start() throws Exception {
100100
EnvVars overrides = run.getEnvironment(taskListener);
101101
HashMap<String, String> overridesMap = new HashMap<String, String>();
102102
overridesMap.put(Constants.JENKINS_BUILD_TAG, overrides.get(Constants.JENKINS_BUILD_TAG));
103+
104+
if ( overrides.containsKey(BrowserStackEnvVars.QEI_URL) ) {
105+
overridesMap.put(BrowserStackEnvVars.QEI_URL, overrides.get(BrowserStackEnvVars.QEI_URL));
106+
}
103107
if ( parentContextEnvVars.containsKey(BrowserStackEnvVars.GRR_JENKINS_KEY) ) {
104108
overridesMap.put(BrowserStackEnvVars.GRR_JENKINS_KEY, parentContextEnvVars.get(BrowserStackEnvVars.GRR_JENKINS_KEY));
105109
}

src/main/java/com/browserstack/automate/ci/jenkins/qualityDashboard/QualityDashboardAPIUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void logToQD(BrowserStackCredentials browserStackCredentials, String logM
7777
ObjectMapper objectMapper = new ObjectMapper();
7878
String jsonBody = objectMapper.writeValueAsString(logMessageObj);
7979
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
80-
makePostRequestToQd(Constants.QualityDashboardAPI.LOG_MESSAGE, browserStackCredentials, requestBody);
80+
makePostRequestToQd(Constants.QualityDashboardAPI.getLogMessageEndpoint(), browserStackCredentials, requestBody);
8181
}
8282
}
8383

src/main/java/com/browserstack/automate/ci/jenkins/qualityDashboard/QualityDashboardInit.java

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static void checkQDIntegrationAndDumpMetaData(BrowserStackCredentials br
9090

9191
private static boolean initialQDSetupRequired(BrowserStackCredentials browserStackCredentials) throws JsonProcessingException {
9292
try {
93-
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.IS_INIT_SETUP_REQUIRED, browserStackCredentials);
93+
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getIsInitSetupRequiredEndpoint(), browserStackCredentials);
9494
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
9595
ResponseBody responseBody = response.body();
9696
if(responseBody != null && responseBody.string().equals("REQUIRED")) {
@@ -105,19 +105,54 @@ private static boolean initialQDSetupRequired(BrowserStackCredentials browserSta
105105
return false;
106106
}
107107

108-
private static List<String> getAllPipelines(BrowserStackCredentials browserStackCredentials) throws JsonProcessingException {
108+
private static List<String> getAllPipelines(BrowserStackCredentials browserStackCredentials) {
109109
List<String> allPipelines = new ArrayList<>();
110110
Jenkins jenkins = Jenkins.getInstanceOrNull();
111+
Integer totalPipelines = 0;
112+
111113
if (jenkins != null) {
114+
totalPipelines = jenkins.getAllItems().size();
112115
jenkins.getAllItems().forEach(job -> {
113-
if(job instanceof WorkflowJob) {
114-
String pipelineName = job.getFullName();
116+
try {
117+
// Logging job details
118+
apiUtil.logToQD(
119+
browserStackCredentials,
120+
String.format(
121+
"Job name: %s, instance type: %s, and is_workflow_job: %s",
122+
job.getName(),
123+
job.getClass().getSimpleName(),
124+
(job instanceof WorkflowJob) ? "yes" : "no"
125+
)
126+
);
127+
} catch (JsonProcessingException e) {
128+
// Handling the exception and logging an error
129+
System.err.println("Error processing JSON for job: " + job.getName());
130+
e.printStackTrace();
131+
}
132+
133+
if (job instanceof WorkflowJob) {
134+
String pipelineName = job.getFullName(); // Getting pipeline name
115135
allPipelines.add(pipelineName);
116136
}
117137
});
118138
} else {
119-
apiUtil.logToQD(browserStackCredentials,"Issue getting Jenkins Instance");
139+
try {
140+
apiUtil.logToQD(browserStackCredentials, "Issue getting Jenkins Instance");
141+
} catch (JsonProcessingException e) {
142+
System.err.println("Error logging issue with Jenkins instance.");
143+
e.printStackTrace();
144+
}
145+
}
146+
147+
try {
148+
apiUtil.logToQD(browserStackCredentials,"Total Pipelines on the jenkins side : " + totalPipelines);
149+
apiUtil.logToQD(browserStackCredentials,"Total Pipelines detected : " + allPipelines.size());
150+
} catch (JsonProcessingException e) {
151+
// Handling the exception and logging an error
152+
System.err.println("Error processing JSON for total pipelines: ");
153+
e.printStackTrace();
120154
}
155+
// Returning the list of filtered pipelines
121156
return allPipelines;
122157
}
123158

@@ -134,7 +169,8 @@ private static boolean sendPipelinesPaginated(BrowserStackCredentials browserSta
134169
PipelinesPaginated pipelinesPaginated = new PipelinesPaginated(page, totalPages, singlePagePipelineList);
135170
String jsonBody = objectMapper.writeValueAsString(pipelinesPaginated);
136171
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
137-
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.SAVE_PIPELINES, browserStackCredentials, requestBody);
172+
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getSavePipelinesEndpoint(), browserStackCredentials, requestBody);
173+
apiUtil.logToQD(browserStackCredentials, "Sending page " + page + " with " + singlePagePipelineList.size() + " pipelines");
138174
if (response == null || response.code() != HttpURLConnection.HTTP_OK) {
139175
apiUtil.logToQD(browserStackCredentials,"Got Non 200 response while saving projects");
140176
isSuccess = false;
@@ -188,7 +224,7 @@ private static void sendBuildsPaginated(BrowserStackCredentials browserStackCred
188224
BuildResultsPaginated buildResultsPaginated = new BuildResultsPaginated(page, totalPages, buildResultList);
189225
String jsonBody = objectMapper.writeValueAsString(buildResultsPaginated);
190226
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
191-
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.SAVE_PIPELINE_RESULTS, browserStackCredentials, requestBody);
227+
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getSavePipelineResultsEndpoint(), browserStackCredentials, requestBody);
192228
if (response == null || response.code() != HttpURLConnection.HTTP_OK) {
193229
apiUtil.logToQD(browserStackCredentials,"Got Non 200 response while saving projects");
194230
break;
@@ -202,7 +238,7 @@ private static void sendBuildsPaginated(BrowserStackCredentials browserStackCred
202238
private static int getHistoryForDays(BrowserStackCredentials browserStackCredentials) {
203239
int no_of_days = 90;
204240
try {
205-
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.HISTORY_FOR_DAYS, browserStackCredentials);
241+
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getHistoryForDaysEndpoint(), browserStackCredentials);
206242
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
207243
ResponseBody responseBody = response.body();
208244
if(responseBody != null) {
@@ -221,7 +257,7 @@ private static int getHistoryForDays(BrowserStackCredentials browserStackCredent
221257
private static int getProjectPageSize(BrowserStackCredentials browserStackCredentials) {
222258
int projectPageSize = 2000;
223259
try {
224-
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.PROJECTS_PAGE_SIZE, browserStackCredentials);
260+
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getProjectsPageSizeEndpoint(), browserStackCredentials);
225261
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
226262
ResponseBody responseBody = response.body();
227263
if(responseBody != null) {
@@ -240,7 +276,7 @@ private static int getProjectPageSize(BrowserStackCredentials browserStackCreden
240276
private static int getResultPageSize(BrowserStackCredentials browserStackCredentials) {
241277
int resultPageSize = 1000;
242278
try {
243-
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.RESULTS_PAGE_SIZE, browserStackCredentials);
279+
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getResultsPageSizeEndpoint(), browserStackCredentials);
244280
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
245281
ResponseBody responseBody = response.body();
246282
if(responseBody != null) {

src/main/java/com/browserstack/automate/ci/jenkins/qualityDashboard/QualityDashboardInitItemListener.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,27 @@ public class QualityDashboardInitItemListener extends ItemListener {
2020

2121
@Override
2222
public void onCreated(Item job) {
23-
String itemName = job.getFullName();
24-
String itemType = getItemTypeModified(job);
25-
if(itemType != null && itemType.equals("PIPELINE")) {
26-
try {
27-
String jsonBody = getJsonReqBody(new ItemUpdate(itemName, itemType));
28-
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.ITEM_CRUD, "POST");
29-
} catch(IOException e) {
30-
e.printStackTrace();
23+
try {
24+
BrowserStackCredentials browserStackCredentials = QualityDashboardUtil.getBrowserStackCreds();
25+
QualityDashboardAPIUtil apiUtil = new QualityDashboardAPIUtil();
26+
apiUtil.logToQD(browserStackCredentials, "Item Created : " + job.getClass().getName()) ;
27+
28+
String itemName = job.getFullName();
29+
String itemType = getItemTypeModified(job);
30+
31+
apiUtil.logToQD(browserStackCredentials, "Item Type : " + itemType + " : " + itemName + " : " + itemType.equals("PIPELINE"));
32+
if(itemType != null && itemType.equals("PIPELINE")) {
33+
try {
34+
apiUtil.logToQD(browserStackCredentials, "Item Type inside the Folder : " + itemType + " : " + itemName + " : " + itemType.equals("PIPELINE"));
35+
String jsonBody = getJsonReqBody(new ItemUpdate(itemName, itemType));
36+
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.getItemCrudEndpoint(), "POST");
37+
38+
} catch(IOException e) {
39+
e.printStackTrace();
40+
}
3141
}
42+
} catch(Exception e) {
43+
e.printStackTrace();
3244
}
3345
}
3446

@@ -39,7 +51,7 @@ public void onDeleted(Item job) {
3951
if(itemType != null) {
4052
try {
4153
String jsonBody = getJsonReqBody(new ItemUpdate(itemName, itemType));
42-
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.ITEM_CRUD, "DELETE");
54+
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.getItemCrudEndpoint(), "DELETE");
4355
} catch(IOException e) {
4456
e.printStackTrace();
4557
}
@@ -54,7 +66,7 @@ public void onRenamed(Item job, String oldName, String newName) {
5466
oldName = job.getParent().getFullName() + "/" + oldName;
5567
newName = job.getParent().getFullName() + "/" + newName;
5668
String jsonBody = getJsonReqBody(new ItemRename(oldName, newName, itemType));
57-
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.ITEM_CRUD, "PUT");
69+
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.getItemCrudEndpoint(), "PUT");
5870
} catch(IOException e) {
5971
e.printStackTrace();
6072
}

src/main/java/com/browserstack/automate/ci/jenkins/qualityDashboard/QualityDashboardPipelineTracker.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private void sendBuildDataToQD(Run run, Result overallResult, String finalZipPat
109109

110110
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
111111
apiUtil.logToQD(browserStackCredentials, "Sending Final Results for jobName: " + jobName + " and buildNumber: " + buildNumber);
112-
apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.STORE_PIPELINE_RESULTS, browserStackCredentials, requestBody);
112+
apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getStorePipelineResultsEndpoint(), browserStackCredentials, requestBody);
113113
} catch(IOException e) {
114114
e.printStackTrace();
115115
}
@@ -153,7 +153,7 @@ private String getUrlForPipeline(Run<?, ?> build) {
153153
}
154154

155155
private boolean isQDEnabled(BrowserStackCredentials browserStackCredentials) throws IOException {
156-
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.IS_QD_ENABLED, browserStackCredentials);
156+
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getIsQdEnabledEndpoint(), browserStackCredentials);
157157
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
158158
ResponseBody responseBody = response.body();
159159
if(responseBody != null && Boolean.parseBoolean(response.body().string())) {
@@ -170,7 +170,7 @@ private boolean isPipelineEnabledForQD(BrowserStackCredentials browserStackCrede
170170
ObjectMapper objectMapper = new ObjectMapper();
171171
String jsonBody = objectMapper.writeValueAsString(getPipelineEnabledObj);
172172
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
173-
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.IS_PIPELINE_ENABLED, browserStackCredentials, requestBody);
173+
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getIsPipelineEnabledEndpoint(), browserStackCredentials, requestBody);
174174
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
175175
ResponseBody responseBody = response.body();
176176
if(responseBody != null && Boolean.parseBoolean(response.body().string())) {
@@ -190,7 +190,7 @@ private String getResultDirForPipeline(String pipelineUrl, BrowserStackCredentia
190190
String jsonBody = objectMapper.writeValueAsString(getResultDirReqObj);
191191

192192
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
193-
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.GET_RESULT_DIRECTORY, browserStackCredentials, requestBody);
193+
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getResultDirectoryEndpoint(), browserStackCredentials, requestBody);
194194
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
195195
String responseBody = response.body() !=null ? response.body().string() : null;
196196
resultDir = responseBody;
@@ -234,7 +234,7 @@ private String uploadZipToQd(String pathToZip, BrowserStackCredentials browserSt
234234
.addFormDataPart("buildNumber", String.valueOf(buildNumber))
235235
.build();
236236

237-
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.UPLOAD_RESULT_ZIP, browserStackCredentials, requestBody);
237+
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getUploadResultZipEndpoint(), browserStackCredentials, requestBody);
238238
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
239239
qdS3Url = response.body() !=null ? response.body().string() : null;
240240
}

0 commit comments

Comments
 (0)