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

Add configuration parameter Zip Name Prefix #100

Open
wants to merge 3 commits 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
22 changes: 20 additions & 2 deletions src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class AWSCodeDeployPublisher extends Publisher implements SimpleBuildStep
private final String awsSecretKey;
private final String credentials;
private final String deploymentMethod;
private final String zipNamePrefix;
private final String versionFileName;

private PrintStream logger;
Expand All @@ -127,6 +128,7 @@ public AWSCodeDeployPublisher(
Long pollingTimeoutSec,
Long pollingFreqSec,
String credentials,
String zipNamePrefix,
String versionFileName,
String deploymentMethod,
String awsAccessKey,
Expand Down Expand Up @@ -155,6 +157,7 @@ public AWSCodeDeployPublisher(
this.proxyPort = proxyPort;
this.credentials = credentials;
this.deploymentMethod = deploymentMethod;
this.zipNamePrefix = zipNamePrefix;
this.versionFileName = versionFileName;
this.awsAccessKey = awsAccessKey;
this.awsSecretKey = awsSecretKey;
Expand Down Expand Up @@ -230,7 +233,14 @@ public void perform(@Nonnull Run<?,?> build, @Nonnull FilePath workspace, @Nonnu

verifyCodeDeployApplication(aws);

final String projectName = build.getDisplayName();
String projectName = null;
logger.println("Zip name prefix: " + this.zipNamePrefix );
if (this.zipNamePrefix != null && this.zipNamePrefix.trim().length() > 0) {
projectName = build.getEnvironment(listener).expand(zipNamePrefix.trim());
} else {
projectName = build.getDisplayName();
}

if (workspace == null) {
throw new IllegalArgumentException("No workspace present for the build.");
}
Expand Down Expand Up @@ -317,6 +327,8 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
File versionFile;
versionFile = new File(sourceDirectory + "/" + versionFileName);

logger.println("Project name: " + projectName + " - Version file path : " + versionFile.getAbsolutePath() + " - Version filename : " + versionFileName);

InputStreamReader reader = null;
String version = null;
try {
Expand All @@ -332,7 +344,9 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
}

if (version != null){
zipFile = new File("/tmp/" + projectName + "-" + version + ".zip");
String tempDir = System.getProperty("java.io.tmpdir");

zipFile = new File(tempDir + File.separator + projectName + "-" + version + ".zip");
final boolean fileCreated = zipFile.createNewFile();
if (!fileCreated) {
logger.println("File already exists, overwriting: " + zipFile.getPath());
Expand Down Expand Up @@ -713,6 +727,10 @@ public String getDeploymentMethod() {
return deploymentMethod;
}

public String getZipNamePrefix() {
return zipNamePrefix;
}

public String getVersionFileName() {
return versionFileName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<f:entry title="Proxy Port" field="proxyPort">
<f:textbox default="" />
</f:entry>
<f:entry title="Zip Name Prefix" field="zipNamePrefix">
<f:textbox />
</f:entry>
<f:entry title="Version File" field="versionFileName">
<f:textbox />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div>
The path to a version file name relative to the subdirectory. The file must contain a version of the application.
If Version file name is set the name of the zip uploaded to S3 will be :
build display name + "-" + version.zip
Or
Zip prefix name + "-" + version.zip
If not set, the name will be
build display name + "-" + generated uid.zip
Or
Zip prefix name + "-" + generated uid.zip
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
The prefix of the name of the zip you wish to deploy to S3. If none is set the display name of the build (ex: #3) will be use.
</div>