Skip to content

Commit 25fc618

Browse files
khushi-mehta-15francisf
authored andcommitted
qei logging changes
1 parent 0c7fbc8 commit 25fc618

File tree

2 files changed

+62
-12
lines changed

2 files changed

+62
-12
lines changed

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

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -135,6 +170,7 @@ private static boolean sendPipelinesPaginated(BrowserStackCredentials browserSta
135170
String jsonBody = objectMapper.writeValueAsString(pipelinesPaginated);
136171
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
137172
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;

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,29 @@ 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.getItemCrudEndpoint(), "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 : " );
27+
apiUtil.logToQD(browserStackCredentials, "Item Created : " + job.getClass().getName()) ;
28+
// apiUtil.logToQD(browserStackCredentials, "Job Type : " + job.getClass().getName() + "---" + job.getFullName() + "---" + job instanceof FreeStyleProject);
29+
30+
String itemName = job.getFullName();
31+
String itemType = getItemTypeModified(job);
32+
33+
apiUtil.logToQD(browserStackCredentials, "Item Type : " + itemType + " : " + itemName + " : " + itemType.equals("PIPELINE"));
34+
if(itemType != null && itemType.equals("PIPELINE")) {
35+
try {
36+
apiUtil.logToQD(browserStackCredentials, "Item Type inside the Folder : " + itemType + " : " + itemName + " : " + itemType.equals("PIPELINE"));
37+
String jsonBody = getJsonReqBody(new ItemUpdate(itemName, itemType));
38+
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.getItemCrudEndpoint(), "POST");
39+
40+
} catch(IOException e) {
41+
e.printStackTrace();
42+
}
3143
}
44+
} catch(Exception e) {
45+
e.printStackTrace();
3246
}
3347
}
3448

0 commit comments

Comments
 (0)