Skip to content
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

Custom zip package name with PackageName parameter #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 17 additions & 6 deletions src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class AWSCodeDeployPublisher extends Publisher {
private final String credentials;
private final String deploymentMethod;
private final String versionFileName;
private final String packageName;

private PrintStream logger;
private Map <String, String> envVars;
Expand Down Expand Up @@ -131,7 +132,8 @@ public AWSCodeDeployPublisher(
String proxyHost,
int proxyPort,
String excludes,
String subdirectory) {
String subdirectory,
String packageName) {

this.externalId = externalId;
this.applicationName = applicationName;
Expand All @@ -154,6 +156,7 @@ public AWSCodeDeployPublisher(
this.awsSecretKey = awsSecretKey;
this.iamRoleArn = iamRoleArn;
this.deploymentGroupAppspec = deploymentGroupAppspec;
this.packageName = packageName;

if (waitForCompletion != null && waitForCompletion) {
this.waitForCompletion = waitForCompletion;
Expand Down Expand Up @@ -221,13 +224,13 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis

verifyCodeDeployApplication(aws);

final String projectName = build.getProject().getName();
final String zipName = getPackageName(build);
final FilePath workspace = build.getWorkspace();
if (workspace == null) {
throw new IllegalArgumentException("No workspace present for the build.");
}
final FilePath sourceDirectory = getSourceDirectory(workspace);
final RevisionLocation revisionLocation = zipAndUpload(aws, projectName, sourceDirectory);
final RevisionLocation revisionLocation = zipAndUpload(aws, zipName, sourceDirectory);

registerRevision(aws, revisionLocation);
if ("onlyRevision".equals(deploymentMethod)){
Expand Down Expand Up @@ -264,6 +267,14 @@ private FilePath getSourceDirectory(FilePath basePath) throws IOException, Inter
return sourcePath;
}

private String getPackageName(AbstractBuild build) {
if (packageName != null && packageName.length() != 0) {
return packageName;
} else {
return build.getProject().getName();;
}
}

private boolean isSubDirectory(FilePath parent, FilePath child) {
FilePath parentFolder = child;
while (parentFolder!=null) {
Expand Down Expand Up @@ -296,7 +307,7 @@ 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, String zipName, FilePath sourceDirectory) throws IOException, InterruptedException, IllegalArgumentException {

File zipFile = null;
File versionFile;
Expand All @@ -317,13 +328,13 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
}

if (version != null){
zipFile = new File("/tmp/" + projectName + "-" + version + ".zip");
zipFile = new File("/tmp/" + zipFilename + "-" + version + ".zip");
final boolean fileCreated = zipFile.createNewFile();
if (!fileCreated) {
logger.println("File already exists, overwriting: " + zipFile.getPath());
}
} else {
zipFile = File.createTempFile(projectName + "-", ".zip");
zipFile = File.createTempFile(zipName + "-", ".zip");
}

String key;
Expand Down