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

Adding option to control Content Behaviour in deployment #76

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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</parent>

<artifactId>codedeploy</artifactId>
<version>1.17-SNAPSHOT</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not adjust the version suffix. SNAPSHOT is for prereleases as we aggregate additional functionality, and then the automated plugin release process will handle removing this and pushing the untagged version to the appropriate release branch.

<version>1.17-CONTENT</version>
<packaging>hpi</packaging>
<groupId>com.amazonaws</groupId>
<name>AWS CodeDeploy Plugin for Jenkins</name>
Expand Down Expand Up @@ -52,9 +52,9 @@

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably better to upload the new aws-sdk to the jenkins maven repo and get it from there

<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.119</version>
<version>1.11.203</version>
</dependency>
</dependencies>

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/amazonaws/codedeploy/AWSClients.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
*
* http://aws.amazon.com/apache2.0
*
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
Expand Down Expand Up @@ -74,20 +74,20 @@ public AWSClients(String region, AWSCredentials credentials, String proxyHost, i
codedeploy.setRegion(Region.getRegion(Regions.fromName(this.region)));
s3.setRegion(Region.getRegion(Regions.fromName(this.region)));
}

public static AWSClients fromDefaultCredentialChain(String region, String proxyHost, int proxyPort) {
return new AWSClients(region, null, proxyHost, proxyPort);
}

public static AWSClients fromIAMRole(String region, String iamRole, String externalId, String proxyHost, int proxyPort) {
return new AWSClients(region, getCredentials(iamRole, externalId), proxyHost, proxyPort);
}

public static AWSClients fromBasicCredentials(String region, String awsAccessKey, String awsSecretKey, String proxyHost, int proxyPort) {
return new AWSClients(region, new BasicAWSCredentials(awsAccessKey, awsSecretKey), proxyHost, proxyPort);
}

/**
/*
* Via the default provider chain (i.e., global keys for this Jenkins instance), return the account ID for the
* currently authenticated user.
* @return 12-digit account id
Expand Down
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 @@ -67,7 +67,7 @@

import javax.servlet.ServletException;

/**
/*
* The AWS CodeDeploy Publisher is a post-build plugin that adds the ability to start a new CodeDeploy deployment
* with the project's workspace as the application revision.
* <p/>
Expand Down 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 fileExistsBehaviour;

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 fileExistsBehaviour) {

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

if (waitForCompletion != null && waitForCompletion) {
this.waitForCompletion = waitForCompletion;
Expand Down Expand Up @@ -419,6 +422,7 @@ private String createDeployment(AWSClients aws, RevisionLocation revisionLocatio
.withApplicationName(getApplicationNameFromEnv())
.withRevision(revisionLocation)
.withDescription("Deployment created by Jenkins")
.withFileExistsBehavior(getFileExistsBehaviour())
);

return createDeploymentResult.getDeploymentId();
Expand Down Expand Up @@ -492,7 +496,7 @@ public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.STEP;
}

/**
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the double **, maven wasn't getting along with this

/*
* Descriptor for {@link AWSCodeDeployPublisher}. Used as a singleton.
* The class is marked as public so that it can be accessed from views.
* <p/>
Expand Down Expand Up @@ -727,6 +731,10 @@ public int getProxyPort() {
return proxyPort;
}

public String getFileExistsBehaviour() {
return fileExistsBehaviour;
}

public String getApplicationNameFromEnv() {
return Util.replaceMacro(this.applicationName, envVars);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@
</f:optionalBlock>
</f:radioBlock>

<f:entry title="ContentOptions">
<f:radioBlock title="Disallow" name="fileExistsBehaviour" value="DISALLOW" checked="${instance.getFileExistsBehaviour() == 'DISALLOW'}" inline="true">
<f:description>
The deployment fails. This is also the default behavior if no option is specified.
</f:description>
</f:radioBlock>

<f:radioBlock title="Overwrite" name="fileExistsBehaviour" value="OVERWRITE" checked="${instance.getFileExistsBehaviour() == 'OVERWRITE'}" inline="true">
<f:description>
The version of the file from the application revision currently being deployed replaces the version already on the instance.
</f:description>
</f:radioBlock>

<f:radioBlock title="Retain" name="fileExistsBehaviour" value="RETAIN" checked="${instance.getFileExistsBehaviour() == 'RETAIN'}" inline="true">
<f:description>
The version of the file already on the instance is kept and used as part of the new deployment.
</f:description>
</f:radioBlock>
</f:entry>

<f:radioBlock title="Use Access/Secret keys" name="credentials" checked="${instance.getCredentials() == 'awsAccessKey'}" inline="true" value="awsAccessKey">
<f:description>
If these keys are left blank, the plugin will attempt to use credentials from the default provider chain. That
Expand Down