31
31
import com .amazonaws .services .codedeploy .model .RegisterApplicationRevisionRequest ;
32
32
import com .amazonaws .services .codedeploy .model .S3Location ;
33
33
34
+ import hudson .AbortException ;
34
35
import hudson .FilePath ;
35
36
import hudson .Launcher ;
36
- import hudson .Extension ;
37
37
import hudson .Util ;
38
- import hudson .model .AbstractBuild ;
39
- import hudson .model .BuildListener ;
38
+ import hudson .Extension ;
40
39
import hudson .model .AbstractProject ;
41
40
import hudson .model .Result ;
41
+ import hudson .model .Run ;
42
+ import hudson .model .TaskListener ;
42
43
import hudson .tasks .BuildStepMonitor ;
43
44
import hudson .tasks .BuildStepDescriptor ;
44
45
import hudson .tasks .Publisher ;
45
46
import hudson .util .DirScanner ;
46
- import hudson .util .FileVisitor ;
47
47
import hudson .util .FormValidation ;
48
48
import hudson .util .ListBoxModel ;
49
- import net . sf . json . JSONException ;
49
+ import jenkins . tasks . SimpleBuildStep ;
50
50
import net .sf .json .JSONObject ;
51
51
52
52
import org .apache .commons .lang .StringUtils ;
65
65
import java .util .Map ;
66
66
import java .util .UUID ;
67
67
68
+ import javax .annotation .Nonnull ;
68
69
import javax .servlet .ServletException ;
69
70
70
71
/**
75
76
* the globally configured keys. This allows the plugin to get temporary credentials instead of requiring permanent
76
77
* credentials to be configured for each project.
77
78
*/
78
- public class AWSCodeDeployPublisher extends Publisher {
79
+ public class AWSCodeDeployPublisher extends Publisher implements SimpleBuildStep {
79
80
public static final long DEFAULT_TIMEOUT_SECONDS = 900 ;
80
81
public static final long DEFAULT_POLLING_FREQUENCY_SECONDS = 15 ;
81
82
public static final String ROLE_SESSION_NAME = "jenkins-codedeploy-plugin" ;
@@ -182,13 +183,13 @@ public AWSCodeDeployPublisher(
182
183
}
183
184
184
185
@ Override
185
- public boolean perform (AbstractBuild build , Launcher launcher , BuildListener listener ) throws IOException , InterruptedException {
186
+ public void perform (@ Nonnull Run <?,?> build , @ Nonnull FilePath workspace , @ Nonnull Launcher launcher , @ Nonnull TaskListener listener ) throws IOException , InterruptedException {
186
187
this .logger = listener .getLogger ();
187
188
envVars = build .getEnvironment (listener );
188
189
final boolean buildFailed = build .getResult () == Result .FAILURE ;
189
190
if (buildFailed ) {
190
191
logger .println ("Skipping CodeDeploy publisher as build failed" );
191
- return true ;
192
+ return ;
192
193
}
193
194
194
195
final AWSClients aws ;
@@ -215,14 +216,13 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
215
216
this .proxyPort );
216
217
}
217
218
218
- boolean success ;
219
+ boolean success = false ;
219
220
220
221
try {
221
222
222
223
verifyCodeDeployApplication (aws );
223
224
224
- final String projectName = build .getProject ().getName ();
225
- final FilePath workspace = build .getWorkspace ();
225
+ final String projectName = build .getDisplayName ();
226
226
if (workspace == null ) {
227
227
throw new IllegalArgumentException ("No workspace present for the build." );
228
228
}
@@ -244,11 +244,11 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
244
244
this .logger .println ("Failed CodeDeploy post-build step; exception follows." );
245
245
this .logger .println (e .getMessage ());
246
246
e .printStackTrace (this .logger );
247
- success = false ;
248
-
249
247
}
250
248
251
- return success ;
249
+ if (!success ) {
250
+ throw new AbortException ();
251
+ }
252
252
}
253
253
254
254
private FilePath getSourceDirectory (FilePath basePath ) throws IOException , InterruptedException {
@@ -492,6 +492,7 @@ public BuildStepMonitor getRequiredMonitorService() {
492
492
}
493
493
494
494
/**
495
+ *
495
496
* Descriptor for {@link AWSCodeDeployPublisher}. Used as a singleton.
496
497
* The class is marked as public so that it can be accessed from views.
497
498
*
0 commit comments