35
35
import com .uber .jenkins .phabricator .unit .UnitTestProvider ;
36
36
import com .uber .jenkins .phabricator .utils .CommonUtils ;
37
37
import com .uber .jenkins .phabricator .utils .Logger ;
38
+
39
+ import hudson .AbortException ;
38
40
import hudson .EnvVars ;
41
+ import hudson .FilePath ;
39
42
import hudson .Launcher ;
40
- import hudson .model .AbstractBuild ;
41
- import hudson .model .BuildListener ;
42
43
import hudson .model .Job ;
43
44
import hudson .model .Result ;
45
+ import hudson .model .Run ;
46
+ import hudson .model .TaskListener ;
44
47
import hudson .tasks .BuildStepMonitor ;
45
48
import hudson .tasks .Notifier ;
46
49
import jenkins .model .CauseOfInterruption ;
47
50
import jenkins .model .InterruptedBuildAction ;
48
51
import jenkins .model .Jenkins ;
52
+ import jenkins .tasks .SimpleBuildStep ;
53
+
49
54
import org .apache .commons .io .FilenameUtils ;
50
55
import org .kohsuke .stapler .DataBoundConstructor ;
51
56
55
60
import java .util .List ;
56
61
import java .util .Set ;
57
62
58
- public class PhabricatorNotifier extends Notifier {
63
+ public class PhabricatorNotifier extends Notifier implements SimpleBuildStep {
59
64
public static final String COBERTURA_CLASS_NAME = "com.uber.jenkins.phabricator.coverage.CoberturaCoverageProvider" ;
60
65
61
66
private static final String JUNIT_PLUGIN_NAME = "junit" ;
@@ -105,8 +110,8 @@ public BuildStepMonitor getRequiredMonitorService() {
105
110
}
106
111
107
112
@ Override
108
- public final boolean perform (final AbstractBuild <?, ?> build , final Launcher launcher ,
109
- final BuildListener listener ) throws InterruptedException , IOException {
113
+ public final void perform (final Run <?, ?> build , FilePath workspace , final Launcher launcher ,
114
+ final TaskListener listener ) throws InterruptedException , IOException {
110
115
EnvVars environment = build .getEnvironment (listener );
111
116
Logger logger = new Logger (listener .getLogger ());
112
117
@@ -128,7 +133,7 @@ public final boolean perform(final AbstractBuild<?, ?> build, final Launcher lau
128
133
if (cause instanceof PhabricatorCauseOfInterruption ) {
129
134
logger .warn (ABORT_TAG , "Skipping notification step since this build was interrupted"
130
135
+ " by a newer build with the same differential revision" );
131
- return true ;
136
+ return ;
132
137
}
133
138
}
134
139
}
@@ -144,7 +149,7 @@ public final boolean perform(final AbstractBuild<?, ?> build, final Launcher lau
144
149
build .addAction (PhabricatorPostbuildAction .createShortText (branch , null ));
145
150
}
146
151
147
- coverageProvider = getCoverageProvider (build , listener , Collections .<String >emptySet ());
152
+ coverageProvider = getCoverageProvider (build , workspace , listener , Collections .<String >emptySet ());
148
153
CodeCoverageMetrics coverageResult = null ;
149
154
if (coverageProvider != null ) {
150
155
coverageResult = coverageProvider .getMetrics ();
@@ -160,7 +165,7 @@ public final boolean perform(final AbstractBuild<?, ?> build, final Launcher lau
160
165
161
166
// Ignore the result.
162
167
nonDifferentialBuildTask .run ();
163
- return true ;
168
+ return ;
164
169
}
165
170
166
171
ConduitAPIClient conduitClient ;
@@ -169,7 +174,7 @@ public final boolean perform(final AbstractBuild<?, ?> build, final Launcher lau
169
174
} catch (ConduitAPIException e ) {
170
175
e .printStackTrace (logger .getStream ());
171
176
logger .warn (CONDUIT_TAG , e .getMessage ());
172
- return false ;
177
+ throw new AbortException () ;
173
178
}
174
179
175
180
final String buildUrl = environment .get ("BUILD_URL" );
@@ -183,7 +188,11 @@ public final boolean perform(final AbstractBuild<?, ?> build, final Launcher lau
183
188
build .getResult (),
184
189
buildUrl
185
190
).run ();
186
- return result == Task .Result .SUCCESS ;
191
+ if (result == Task .Result .SUCCESS ) {
192
+ return ;
193
+ } else {
194
+ throw new AbortException ();
195
+ }
187
196
}
188
197
189
198
DifferentialClient diffClient = new DifferentialClient (diffID , conduitClient );
@@ -194,7 +203,7 @@ public final boolean perform(final AbstractBuild<?, ?> build, final Launcher lau
194
203
e .printStackTrace (logger .getStream ());
195
204
logger .warn (CONDUIT_TAG , "Unable to fetch differential from Conduit API" );
196
205
logger .warn (CONDUIT_TAG , e .getMessage ());
197
- return true ;
206
+ return ;
198
207
}
199
208
200
209
if (needsDecoration ) {
@@ -206,7 +215,7 @@ public final boolean perform(final AbstractBuild<?, ?> build, final Launcher lau
206
215
includeFileNames .add (FilenameUtils .getName (file ));
207
216
}
208
217
209
- coverageProvider = getCoverageProvider (build , listener , includeFileNames );
218
+ coverageProvider = getCoverageProvider (build , workspace , listener , includeFileNames );
210
219
CodeCoverageMetrics coverageResult = null ;
211
220
if (coverageProvider != null ) {
212
221
coverageResult = coverageProvider .getMetrics ();
@@ -215,6 +224,7 @@ public final boolean perform(final AbstractBuild<?, ?> build, final Launcher lau
215
224
BuildResultProcessor resultProcessor = new BuildResultProcessor (
216
225
logger ,
217
226
build ,
227
+ workspace ,
218
228
diff ,
219
229
diffClient ,
220
230
environment .get (PhabricatorPlugin .PHID_FIELD ),
@@ -247,14 +257,12 @@ public final boolean perform(final AbstractBuild<?, ?> build, final Launcher lau
247
257
248
258
// Fail the build if we can't report to Harbormaster
249
259
if (!resultProcessor .processHarbormaster ()) {
250
- return false ;
260
+ throw new AbortException () ;
251
261
}
252
262
253
263
resultProcessor .processRemoteComment (commentFile , commentSize );
254
264
255
265
resultProcessor .sendComment (commentWithConsoleLinkOnFailure );
256
-
257
- return true ;
258
266
}
259
267
260
268
protected UberallsClient getUberallsClient (Logger logger , String gitUrl , String branch ) {
@@ -291,9 +299,15 @@ private ConduitAPIClient getConduitClient(Job owner) throws ConduitAPIException
291
299
* @param listener The build listener
292
300
* @return The current cobertura coverage, if any
293
301
*/
294
- private CoverageProvider getCoverageProvider (AbstractBuild build , BuildListener listener ,
302
+ private CoverageProvider getCoverageProvider (Run <?, ?> build , FilePath workspace , TaskListener listener ,
295
303
Set <String > includeFileNames ) {
296
- if (!build .getResult ().isBetterOrEqualTo (Result .UNSTABLE )) {
304
+ Result buildResult = null ;
305
+ if (build .getResult () == null ) {
306
+ buildResult = Result .SUCCESS ;
307
+ } else {
308
+ buildResult = build .getResult ();
309
+ }
310
+ if (!buildResult .isBetterOrEqualTo (Result .UNSTABLE )) {
297
311
return null ;
298
312
}
299
313
@@ -311,6 +325,7 @@ private CoverageProvider getCoverageProvider(AbstractBuild build, BuildListener
311
325
}
312
326
313
327
coverage .setBuild (build );
328
+ coverage .setWorkspace (workspace );
314
329
coverage .setIncludeFileNames (includeFileNames );
315
330
coverage .setCoverageReportPattern (coverageReportPattern );
316
331
if (coverage .hasCoverage ()) {
@@ -321,7 +336,7 @@ private CoverageProvider getCoverageProvider(AbstractBuild build, BuildListener
321
336
}
322
337
}
323
338
324
- private UnitTestProvider getUnitProvider (AbstractBuild build , BuildListener listener ) {
339
+ private UnitTestProvider getUnitProvider (Run <?, ?> build , TaskListener listener ) {
325
340
Logger logger = new Logger (listener .getLogger ());
326
341
327
342
InstanceProvider <UnitTestProvider > provider = new InstanceProvider <UnitTestProvider >(
0 commit comments