3131import com .amazonaws .services .codedeploy .model .RegisterApplicationRevisionRequest ;
3232import com .amazonaws .services .codedeploy .model .S3Location ;
3333
34+ import hudson .AbortException ;
3435import hudson .FilePath ;
3536import hudson .Launcher ;
36- import hudson .Extension ;
3737import hudson .Util ;
38- import hudson .model .AbstractBuild ;
39- import hudson .model .BuildListener ;
38+ import hudson .Extension ;
4039import hudson .model .AbstractProject ;
4140import hudson .model .Result ;
41+ import hudson .model .Run ;
42+ import hudson .model .TaskListener ;
4243import hudson .tasks .BuildStepMonitor ;
4344import hudson .tasks .BuildStepDescriptor ;
4445import hudson .tasks .Publisher ;
4546import hudson .util .DirScanner ;
46- import hudson .util .FileVisitor ;
4747import hudson .util .FormValidation ;
4848import hudson .util .ListBoxModel ;
49- import net . sf . json . JSONException ;
49+ import jenkins . tasks . SimpleBuildStep ;
5050import net .sf .json .JSONObject ;
5151
5252import org .apache .commons .lang .StringUtils ;
6565import java .util .Map ;
6666import java .util .UUID ;
6767
68+ import javax .annotation .Nonnull ;
6869import javax .servlet .ServletException ;
6970
7071/**
7576 * the globally configured keys. This allows the plugin to get temporary credentials instead of requiring permanent
7677 * credentials to be configured for each project.
7778 */
78- public class AWSCodeDeployPublisher extends Publisher {
79+ public class AWSCodeDeployPublisher extends Publisher implements SimpleBuildStep {
7980 public static final long DEFAULT_TIMEOUT_SECONDS = 900 ;
8081 public static final long DEFAULT_POLLING_FREQUENCY_SECONDS = 15 ;
8182 public static final String ROLE_SESSION_NAME = "jenkins-codedeploy-plugin" ;
@@ -182,13 +183,13 @@ public AWSCodeDeployPublisher(
182183 }
183184
184185 @ 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 {
186187 this .logger = listener .getLogger ();
187188 envVars = build .getEnvironment (listener );
188189 final boolean buildFailed = build .getResult () == Result .FAILURE ;
189190 if (buildFailed ) {
190191 logger .println ("Skipping CodeDeploy publisher as build failed" );
191- return true ;
192+ return ;
192193 }
193194
194195 final AWSClients aws ;
@@ -215,14 +216,13 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
215216 this .proxyPort );
216217 }
217218
218- boolean success ;
219+ boolean success = false ;
219220
220221 try {
221222
222223 verifyCodeDeployApplication (aws );
223224
224- final String projectName = build .getProject ().getName ();
225- final FilePath workspace = build .getWorkspace ();
225+ final String projectName = build .getDisplayName ();
226226 if (workspace == null ) {
227227 throw new IllegalArgumentException ("No workspace present for the build." );
228228 }
@@ -244,11 +244,11 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
244244 this .logger .println ("Failed CodeDeploy post-build step; exception follows." );
245245 this .logger .println (e .getMessage ());
246246 e .printStackTrace (this .logger );
247- success = false ;
248-
249247 }
250248
251- return success ;
249+ if (!success ) {
250+ throw new AbortException ();
251+ }
252252 }
253253
254254 private FilePath getSourceDirectory (FilePath basePath ) throws IOException , InterruptedException {
@@ -492,6 +492,7 @@ public BuildStepMonitor getRequiredMonitorService() {
492492 }
493493
494494 /**
495+ *
495496 * Descriptor for {@link AWSCodeDeployPublisher}. Used as a singleton.
496497 * The class is marked as public so that it can be accessed from views.
497498 *
0 commit comments