Skip to content

Commit c2aed08

Browse files
authored
Merge pull request #17 from awslabs/master
Merging Pipeline support to jenkinsci
2 parents b50b30c + 716aa3e commit c2aed08

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Setting up
1616
After building and installing the plugin, some simple configuration is needed
1717
for your project.
1818

19+
**Freestyle**
20+
1921
1. Open up your project configuration
2022
1. In the `Post-build Actions` section, select "Deploy an application to AWS
2123
CodeDeploy"
@@ -29,6 +31,18 @@ associated role has, at minimum, a policy that permits `codedeploy:*` and
2931
1. Temporary access keys. These will use the global keys from the Jenkins
3032
instance.
3133

34+
**Pipeline**
35+
36+
1. Create a [Jenkins Pipeline](https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin) project
37+
1. Use the Pipeline Snippet Generator
38+
1. For 'Sample Step', choose 'step: General Build Step'
39+
1. For 'Build Step', choose 'Deploy an application to AWS CodeDeploy'
40+
1. populate variables and then 'Generate Groovy'
41+
42+
Here is a rather blank example:
43+
44+
step([$class: 'AWSCodeDeployPublisher', applicationName: '', awsAccessKey: '', awsSecretKey: '', credentials: 'awsAccessKey', deploymentGroupAppspec: false, deploymentGroupName: '', deploymentMethod: 'deploy', excludes: '', iamRoleArn: '', includes: '**', proxyHost: '', proxyPort: 0, region: 'ap-northeast-1', s3bucket: '', s3prefix: '', subdirectory: '', versionFileName: '', waitForCompletion: false])
45+
3246
License
3347
-------
3448

src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@
3131
import com.amazonaws.services.codedeploy.model.RegisterApplicationRevisionRequest;
3232
import com.amazonaws.services.codedeploy.model.S3Location;
3333

34+
import hudson.AbortException;
3435
import hudson.FilePath;
3536
import hudson.Launcher;
36-
import hudson.Extension;
3737
import hudson.Util;
38-
import hudson.model.AbstractBuild;
39-
import hudson.model.BuildListener;
38+
import hudson.Extension;
4039
import hudson.model.AbstractProject;
4140
import hudson.model.Result;
41+
import hudson.model.Run;
42+
import hudson.model.TaskListener;
4243
import hudson.tasks.BuildStepMonitor;
4344
import hudson.tasks.BuildStepDescriptor;
4445
import hudson.tasks.Publisher;
4546
import hudson.util.DirScanner;
46-
import hudson.util.FileVisitor;
4747
import hudson.util.FormValidation;
4848
import hudson.util.ListBoxModel;
49-
import net.sf.json.JSONException;
49+
import jenkins.tasks.SimpleBuildStep;
5050
import net.sf.json.JSONObject;
5151

5252
import org.apache.commons.lang.StringUtils;
@@ -65,6 +65,7 @@
6565
import java.util.Map;
6666
import java.util.UUID;
6767

68+
import javax.annotation.Nonnull;
6869
import javax.servlet.ServletException;
6970

7071
/**
@@ -75,7 +76,7 @@
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

Comments
 (0)