Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 8afb9e2

Browse files
authored
Add skip reason for skipped tasks in build results table (#356)
* Add skipReason in build results table * add skip reason texts * add test and bump Maven task * remove .idea from gitignore in this branch * update as per review comments * update as per review * update function name * update build results table * update test * update skip link * update status to succeeded * update data constructor
1 parent 090ee01 commit 8afb9e2

File tree

10 files changed

+113
-49
lines changed

10 files changed

+113
-49
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trigger:
1919
- master
2020

2121
steps:
22-
- task: Maven@3
22+
- task: Maven@4
2323
inputs:
2424
mavenPomFile: 'pom.xml'
2525
mavenOptions: '-Xmx3072m -Dmaven.javadoc.skip=true'

src/main/java/com/mathworks/ci/BuildArtifactAction.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private void setCounts() throws InterruptedException, ParseException {
206206
private void iterateAllTaskAttributes(Entry pair, BuildArtifactData data) {
207207
// Iterates across all task attributes and updates
208208
String key = pair.getKey().toString();
209-
switch(key.toLowerCase()){
209+
switch(key){
210210
case "duration":
211211
data.setTaskDuration(pair.getValue().toString());
212212
break;
@@ -222,6 +222,26 @@ private void iterateAllTaskAttributes(Entry pair, BuildArtifactData data) {
222222
case "skipped":
223223
data.setTaskSkipped((Boolean) pair.getValue());
224224
break;
225+
case "skipReason":
226+
String skipReasonKey = pair.getValue().toString();
227+
String skipReason;
228+
switch(skipReasonKey){
229+
case "UpToDate":
230+
skipReason = "up-to-date";
231+
break;
232+
case "UserSpecified":
233+
case "UserRequested":
234+
skipReason = "user requested";
235+
break;
236+
case "DependencyFailed":
237+
skipReason = "dependency failed";
238+
break;
239+
default:
240+
skipReason = skipReasonKey;
241+
break;
242+
}
243+
data.setSkipReason(skipReason);
244+
break;
225245
default :
226246
break;
227247
}

src/main/java/com/mathworks/ci/BuildArtifactData.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class BuildArtifactData {
1313

1414
private String taskDescription;
1515
private boolean taskSkipped;
16+
private String skipReason;
1617

1718
public BuildArtifactData() {
1819
}
@@ -41,6 +42,14 @@ public void setTaskSkipped(boolean taskSkipped) {
4142
this.taskSkipped = taskSkipped;
4243
}
4344

45+
public String getSkipReason() {
46+
return (this.skipReason == null) ? "" : this.skipReason;
47+
}
48+
49+
public void setSkipReason(String skipReason) {
50+
this.skipReason = skipReason;
51+
}
52+
4453
public boolean getTaskFailed() {
4554
return this.taskFailed;
4655
}

src/main/resources/+ciplugins/+jenkins/BuildReportPlugin.m

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,48 @@
22

33
% Copyright 2024 The MathWorks, Inc.
44

5-
methods (Access=protected)
5+
properties
6+
TaskDetails = {};
7+
end
68

9+
methods (Access=protected)
710
function runTaskGraph(plugin, pluginData)
811
runTaskGraph@matlab.buildtool.plugins.BuildRunnerPlugin(plugin, pluginData);
12+
913
[fID, msg] = fopen(fullfile(getenv("MW_MATLAB_TEMP_FOLDER"),"buildArtifact.json"), "w");
1014
if fID == -1
1115
warning("ciplugins:jenkins:BuildReportPlugin:UnableToOpenFile","Could not open a file for Jenkins build result table due to: %s", msg);
1216
else
1317
closeFile = onCleanup(@()fclose(fID));
14-
taskDetails = struct();
15-
for idx = 1:numel(pluginData.TaskResults)
16-
taskDetails(idx).name = pluginData.TaskResults(idx).Name;
17-
taskDetails(idx).description = pluginData.TaskGraph.Tasks(idx).Description;
18-
taskDetails(idx).failed = pluginData.TaskResults(idx).Failed;
19-
taskDetails(idx).skipped = pluginData.TaskResults(idx).Skipped;
20-
taskDetails(idx).duration = string(pluginData.TaskResults(idx).Duration);
21-
end
22-
a = struct("taskDetails",taskDetails);
23-
s = jsonencode(a,PrettyPrint=true);
24-
fprintf(fID, "%s",s);
18+
a = struct();
19+
a.taskDetails = plugin.TaskDetails;
20+
s = jsonencode(a, PrettyPrint=true);
21+
fprintf(fID, "%s", s);
2522
end
2623
end
24+
25+
function runTask(plugin, pluginData)
26+
runTask@matlab.buildtool.plugins.BuildRunnerPlugin(plugin, pluginData);
27+
28+
taskDetail = getCommonTaskDetail(pluginData);
29+
plugin.TaskDetails = [plugin.TaskDetails, taskDetail];
30+
end
31+
32+
function skipTask(plugin, pluginData)
33+
skipTask@matlab.buildtool.plugins.BuildRunnerPlugin(plugin, pluginData);
34+
35+
taskDetail = getCommonTaskDetail(pluginData);
36+
taskDetail.skipReason = pluginData.SkipReason;
37+
plugin.TaskDetails = [plugin.TaskDetails, taskDetail];
38+
end
2739
end
2840
end
41+
42+
function taskDetail = getCommonTaskDetail(pluginData)
43+
taskDetail = struct();
44+
taskDetail.name = pluginData.TaskResults.Name;
45+
taskDetail.description = pluginData.TaskGraph.Tasks.Description;
46+
taskDetail.failed = pluginData.TaskResults.Failed;
47+
taskDetail.skipped = pluginData.TaskResults.Skipped;
48+
taskDetail.duration = string(pluginData.TaskResults.Duration);
49+
end

src/main/resources/com/mathworks/ci/BuildArtifactAction/index.jelly

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<?jelly escape-by-default='true'?>
32
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
43
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:r="/lib/hudson/test" xmlns:p="/lib/test">
@@ -23,20 +22,20 @@
2322
(${h.getDiffString(it.failCount-prev.failCount)})
2423
</j:if>
2524
<j:if test="${it.skipCount > 0}">
26-
, Skipped ${(it.skipCount)}
25+
, ${(it.skipCount)} Skipped
2726
<j:if test="${prev!=null}">
2827
(${h.getDiffString(it.skipCount-prev.skipCount)})
2928
</j:if>
3029
</j:if>
3130
</div>
32-
<div style="width:100%; height:1em; background-color: #729FCF; border-radius: 6px; overflow: hidden;">
31+
<div style="width:100%; height:1em; background-color: mediumseagreen; border-radius: 6px; overflow: hidden;">
3332
<!-- Failed task part of the bar. -->
34-
<div style="width:${it.failCount*100/it.totalCount}%; height: 1em; background-color: #EF2929; float: right;"></div>
33+
<div style="width:${it.failCount*100/it.totalCount}%; height: 1em; background-color: crimson; float: right;"></div>
3534
<!-- Skipped task part of the bar. -->
36-
<div style="width:${it.skipCount*100/it.totalCount}%; height: 1em; background-color: #FCE94F; float: right;"></div>
35+
<div style="width:${it.skipCount*100/it.totalCount}%; height: 1em; background-color: steelblue; float: right;"></div>
3736
</div>
3837
<div align="right">
39-
${(it.failCount)} Failures
38+
${(it.failCount)} Failed
4039
<j:if test="${prev!=null}">
4140
(${h.getDiffString(it.totalCount-prev.totalCount)})
4241
</j:if>
@@ -48,10 +47,10 @@
4847
<table class="jenkins-table sortable" id="buildresults">
4948
<thead>
5049
<tr>
51-
<th class="pane-header" style="width:6em">Task Name</th>
50+
<th class="pane-header" style="width:6em" tooltip="Task name">Task</th>
5251
<th class="pane-header" style="width:6em">Status </th>
5352
<th class="pane-header">Description</th>
54-
<th class="pane-header" style="width:6em">Duration (HH:MM:SS)</th>
53+
<th class="pane-header" style="width:6em">Duration (HH:mm:ss)</th>
5554
</tr>
5655
</thead>
5756

@@ -66,28 +65,25 @@
6665
<a href="../console#matlab-${p.taskName}">${p.taskName}</a>
6766
</j:if>
6867
</td>
69-
<td class="pane" style="width:9em">
68+
<td class="pane no-wrap" style="width:auto">
7069
<span class="${pst.cssClass}">
7170
<j:if test="${p.taskFailed != false}">
72-
<j:if test="${it.actionID != ''}">
73-
<a href="../console#matlab-${p.taskName}-${it.actionID}"><font color="#EF2929"> FAILED </font> </a>
74-
</j:if>
75-
<j:if test="${it.actionID == ''}">
76-
<a href="../console#matlab-${p.taskName}"><font color="#EF2929"> FAILED </font> </a>
77-
</j:if>
71+
<a href="../console#matlab-${p.taskName}${it.actionID != '' ? '-' + it.actionID : ''}" style="color: crimson;">
72+
Failed
73+
</a>
7874
</j:if>
7975
<j:if test="${p.taskFailed == false}">
8076
<j:if test="${p.taskSkipped == false}">
81-
<font color="#729FCF"> PASSED </font>
77+
<font color="mediumseagreen"> Succeeded </font>
8278
</j:if>
8379
</j:if>
8480
<j:if test="${p.taskSkipped == true}">
85-
<j:if test="${it.actionID != ''}">
86-
<a href="../console#matlab-${p.taskName}-${it.actionID}"><font color="#FCE94F"> SKIPPED </font> </a>
87-
</j:if>
88-
<j:if test="${it.actionID == ''}">
89-
<a href="../console#matlab-${p.taskName}"><font color="#FCE94F"> SKIPPED </font> </a>
90-
</j:if>
81+
<a href="../console#matlab-${p.taskName}${it.actionID != '' ? '-' + it.actionID : ''}" style="color: steelblue;">
82+
Skipped
83+
<j:if test="${p.skipReason != ''}">
84+
(${p.skipReason})
85+
</j:if>
86+
</a>
9187
</j:if>
9288
</span>
9389
</td>

src/main/resources/com/mathworks/ci/BuildArtifactAction/summary.jelly

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@
99
<p><a href="${it.urlName}">MATLAB Build Results</a></p>
1010
<span class="${pst.cssClass}">
1111
<j:if test="${it.totalCount == 0}">
12-
<font color="#EF2929"><h5>Unable to generate a build artifact. </h5></font>
12+
<font color="crimson"><h5>Unable to generate a build artifact. </h5></font>
1313
</j:if>
1414
</span>
15-
<p>
16-
<b>Tasks run: <font color="Blue">${it.totalCount}</font></b>
17-
<br></br>
18-
<br>
19-
<b>Failed: <font color="red">${it.failCount}</font></b>
20-
</br>
21-
<br>
22-
<b>Skipped: <font color="orange">${it.skipCount}</font></b>
23-
</br>
24-
</p>
15+
<p><b>Tasks run: <font color="mediumseagreen">${it.totalCount}</font></b></p>
16+
<br>
17+
<b>Failed: <font color="crimson">${it.failCount}</font></b>
18+
</br>
19+
<br>
20+
<b>Skipped: <font color="steelblue">${it.skipCount}</font></b>
21+
</br>
2522
</t:summary>
2623
</j:jelly>

src/main/resources/com/mathworks/ci/MatlabBuilder/config.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
33

4-
<font color="red">Using this build step is not recommended and will be removed in a feature release. Use “Run MATLAB Tests” or “Run MATLAB Command” instead.</font>
4+
<font color="crimson">Using this build step is not recommended and will be removed in a feature release. Use “Run MATLAB Tests” or “Run MATLAB Command” instead.</font>
55
<f:section>
66
<f:entry title="MATLAB root " field="matlabRoot">
77
<f:textbox disabled="disabled" checkMethod="post" />

src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void verifyFailedCount() throws ExecutionException, InterruptedException,
100100
copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json",targetFile,artifactRoot);
101101
List<BuildArtifactData> ba = ac.getBuildArtifact();
102102
boolean expectedStatus = ba.get(0).getTaskFailed();
103-
Assert.assertEquals("The task is passed",false,expectedStatus);
103+
Assert.assertEquals("The task succeeded",false,expectedStatus);
104104
}
105105

106106
/**
@@ -120,6 +120,24 @@ public void verifySkipCount() throws ExecutionException, InterruptedException, U
120120
Assert.assertEquals("The task is not skipped",true,ba.get(0).getTaskSkipped());
121121
}
122122

123+
/**
124+
* Verify if skip reason is returned from artifact file.
125+
*
126+
*/
127+
128+
@Test
129+
public void verifySkipReasonIsAccurate() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException {
130+
FreeStyleBuild build = getFreestyleBuild();
131+
final String actionID = "abc123";
132+
final String targetFile = "buildArtifact"+ actionID + ".json";
133+
BuildArtifactAction ac = new BuildArtifactAction(build, actionID);
134+
FilePath artifactRoot = new FilePath(build.getRootDir());
135+
copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json",targetFile,artifactRoot);
136+
List<BuildArtifactData> ba = ac.getBuildArtifact();
137+
Assert.assertEquals("The task is not skipped",true,ba.get(0).getTaskSkipped());
138+
Assert.assertEquals("The skip reason for skipped task is inaccurate","user requested",ba.get(0).getSkipReason());
139+
}
140+
123141
/**
124142
* Verify if duration returned from artifact file.
125143
*
@@ -219,6 +237,7 @@ public void verifyTotalFailedTaskCountIsAccurate() throws ExecutionException, In
219237
Assert.assertEquals("Total task count is not correct",3,ac.getTotalCount());
220238
Assert.assertEquals("Total task failed count is not correct",1,ac.getFailCount());
221239
}
240+
222241
/**
223242
* Verify if total skipped count returned from artifact file.
224243
*

src/test/resources/buildArtifacts/t1/buildArtifact.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"description": "tests Dscription",
2020
"failed": false,
2121
"skipped": true,
22+
"skipReason": "UserSpecified",
2223
"duration": "00:00:00"
2324
}
2425
]

src/test/resources/buildArtifacts/t2/buildArtifact.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Test show",
55
"failed": false,
66
"skipped": true,
7+
"skipReason": "UserSpecified",
78
"duration": "00:02:53"
89
}
910
}

0 commit comments

Comments
 (0)