31
31
import com .amazonaws .services .codedeploy .model .RegisterApplicationRevisionRequest ;
32
32
import com .amazonaws .services .codedeploy .model .S3Location ;
33
33
34
- import hudson .FilePath ;
35
- import hudson .Launcher ;
36
- import hudson .Extension ;
37
- import hudson .Util ;
38
- import hudson .model .AbstractBuild ;
39
- import hudson .model .BuildListener ;
40
- import hudson .model .AbstractProject ;
41
- import hudson .model .Result ;
34
+ import hudson .*;
35
+ import hudson .model .*;
42
36
import hudson .tasks .BuildStepMonitor ;
43
37
import hudson .tasks .BuildStepDescriptor ;
44
38
import hudson .tasks .Publisher ;
45
39
import hudson .util .DirScanner ;
46
40
import hudson .util .FileVisitor ;
47
41
import hudson .util .FormValidation ;
48
42
import hudson .util .ListBoxModel ;
43
+ import jenkins .tasks .SimpleBuildStep ;
49
44
import net .sf .json .JSONException ;
50
45
import net .sf .json .JSONObject ;
51
46
65
60
import java .util .Map ;
66
61
import java .util .UUID ;
67
62
63
+ import javax .annotation .Nonnull ;
68
64
import javax .servlet .ServletException ;
69
65
70
66
/**
71
67
* The AWS CodeDeploy Publisher is a post-build plugin that adds the ability to start a new CodeDeploy deployment
72
68
* with the project's workspace as the application revision.
73
- * <p/>
69
+ *
74
70
* To configure, users must create an IAM role that allows "S3" and "CodeDeploy" actions and must be assumable by
75
71
* the globally configured keys. This allows the plugin to get temporary credentials instead of requiring permanent
76
72
* credentials to be configured for each project.
77
73
*/
78
- public class AWSCodeDeployPublisher extends Publisher {
74
+ public class AWSCodeDeployPublisher extends Publisher implements SimpleBuildStep {
79
75
public static final long DEFAULT_TIMEOUT_SECONDS = 900 ;
80
76
public static final long DEFAULT_POLLING_FREQUENCY_SECONDS = 15 ;
81
77
public static final String ROLE_SESSION_NAME = "jenkins-codedeploy-plugin" ;
@@ -182,13 +178,13 @@ public AWSCodeDeployPublisher(
182
178
}
183
179
184
180
@ Override
185
- public boolean perform (AbstractBuild build , Launcher launcher , BuildListener listener ) throws IOException , InterruptedException {
181
+ public void perform (@ Nonnull Run <?,?> build , @ Nonnull FilePath workspace , @ Nonnull Launcher launcher , @ Nonnull TaskListener listener ) throws IOException , InterruptedException {
186
182
this .logger = listener .getLogger ();
187
183
envVars = build .getEnvironment (listener );
188
184
final boolean buildFailed = build .getResult () == Result .FAILURE ;
189
185
if (buildFailed ) {
190
186
logger .println ("Skipping CodeDeploy publisher as build failed" );
191
- return true ;
187
+ return ;
192
188
}
193
189
194
190
final AWSClients aws ;
@@ -215,14 +211,13 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
215
211
this .proxyPort );
216
212
}
217
213
218
- boolean success ;
214
+ boolean success = false ;
219
215
220
216
try {
221
217
222
218
verifyCodeDeployApplication (aws );
223
219
224
- final String projectName = build .getProject ().getName ();
225
- final FilePath workspace = build .getWorkspace ();
220
+ final String projectName = build .getDisplayName ();
226
221
if (workspace == null ) {
227
222
throw new IllegalArgumentException ("No workspace present for the build." );
228
223
}
@@ -244,11 +239,11 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
244
239
this .logger .println ("Failed CodeDeploy post-build step; exception follows." );
245
240
this .logger .println (e .getMessage ());
246
241
e .printStackTrace (this .logger );
247
- success = false ;
248
-
249
242
}
250
243
251
- return success ;
244
+ if (!success ) {
245
+ throw new AbortException ();
246
+ }
252
247
}
253
248
254
249
private FilePath getSourceDirectory (FilePath basePath ) throws IOException , InterruptedException {
@@ -493,10 +488,10 @@ public BuildStepMonitor getRequiredMonitorService() {
493
488
}
494
489
495
490
/**
491
+ *
496
492
* Descriptor for {@link AWSCodeDeployPublisher}. Used as a singleton.
497
493
* The class is marked as public so that it can be accessed from views.
498
- * <p/>
499
- * <p/>
494
+ *
500
495
* See <tt>src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/*.jelly</tt>
501
496
* for the actual HTML fragment for the configuration screen.
502
497
*/
0 commit comments