Skip to content

Expose AWS_CODEDEPLOY_S3_KEY variable in the ENV #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
import hudson.Launcher;
import hudson.Extension;
import hudson.Util;
import hudson.EnvVars;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.AbstractProject;
import hudson.model.Result;
import hudson.model.Environment;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Publisher;
Expand Down Expand Up @@ -78,6 +80,7 @@ public class AWSCodeDeployPublisher extends Publisher {
public static final long DEFAULT_TIMEOUT_SECONDS = 900;
public static final long DEFAULT_POLLING_FREQUENCY_SECONDS = 15;
public static final String ROLE_SESSION_NAME = "jenkins-codedeploy-plugin";
public static final String AWS_CODEDEPLOY_S3_KEY = "AWS_CODEDEPLOY_S3_KEY";
public static final Regions[] AVAILABLE_REGIONS = {Regions.AP_NORTHEAST_1, Regions.AP_SOUTHEAST_1, Regions.AP_SOUTHEAST_2, Regions.EU_WEST_1, Regions.US_EAST_1, Regions.US_WEST_2, Regions.EU_CENTRAL_1, Regions.US_WEST_1, Regions.SA_EAST_1, Regions.AP_NORTHEAST_2};

private final String s3bucket;
Expand Down Expand Up @@ -220,8 +223,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis

verifyCodeDeployApplication(aws);

String projectName = build.getProject().getName();
RevisionLocation revisionLocation = zipAndUpload(aws, projectName, getSourceDirectory(build.getWorkspace()));
RevisionLocation revisionLocation = zipAndUpload(aws, build);

registerRevision(aws, revisionLocation);
if ("onlyRevision".equals(deploymentMethod)){
Expand Down Expand Up @@ -290,7 +292,9 @@ private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentE
}
}

private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath sourceDirectory) throws IOException, InterruptedException, IllegalArgumentException {
private RevisionLocation zipAndUpload(AWSClients aws, AbstractBuild build) throws IOException, InterruptedException, IllegalArgumentException {
String projectName = build.getProject().getName();
FilePath sourceDirectory = getSourceDirectory(build.getWorkspace());

File zipFile = null;
File versionFile;
Expand Down Expand Up @@ -374,6 +378,10 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
revisionLocation.setRevisionType(RevisionLocationType.S3);
revisionLocation.setS3Location(s3Location);

envVars.put(AWS_CODEDEPLOY_S3_KEY, key);
EnvVars envVarsObject = new EnvVars(envVars);
build.getEnvironments().set(0, Environment.create(envVarsObject));

return revisionLocation;
} finally {
zipFile.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
href="http://alpha-docs-aws.amazon.com/codedeploy/latest/userguide/how-to-create-application.html">How
to create an Application with AWS CodeDeploy</a> documentation. You can use environment variables
in this field.
<div>
Available environments values:
<ul>
<li>AWS_CODEDEPLOY_S3_KEY</li>
</ul>
</div>
</div>