Skip to content

Commit 6f191f1

Browse files
Amine FattouchJeremy Cerri
Amine Fattouch
authored and
Jeremy Cerri
committed
Add support for environment variables defined in jenkins build
1 parent 5e07b16 commit 6f191f1

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
66
* A copy of the License is located at
7-
*
7+
*
88
* http://aws.amazon.com/apache2.0
9-
*
9+
*
1010
* or in the "license" file accompanying this file. This file is distributed
1111
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
1212
* express or implied. See the License for the specific language governing
@@ -74,15 +74,15 @@ public AWSClients(String region, AWSCredentials credentials, String proxyHost, i
7474
codedeploy.setRegion(Region.getRegion(Regions.fromName(this.region)));
7575
s3.setRegion(Region.getRegion(Regions.fromName(this.region)));
7676
}
77-
77+
7878
public static AWSClients fromDefaultCredentialChain(String region, String proxyHost, int proxyPort) {
7979
return new AWSClients(region, null, proxyHost, proxyPort);
8080
}
81-
81+
8282
public static AWSClients fromIAMRole(String region, String iamRole, String externalId, String proxyHost, int proxyPort) {
8383
return new AWSClients(region, getCredentials(iamRole, externalId), proxyHost, proxyPort);
8484
}
85-
85+
8686
public static AWSClients fromBasicCredentials(String region, String awsAccessKey, String awsSecretKey, String proxyHost, int proxyPort) {
8787
return new AWSClients(region, new BasicAWSCredentials(awsAccessKey, awsSecretKey), proxyHost, proxyPort);
8888
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,21 @@ public void perform(@Nonnull Run<?,?> build, @Nonnull FilePath workspace, @Nonnu
200200
this.proxyHost,
201201
this.proxyPort);
202202
} else {
203-
aws = AWSClients.fromBasicCredentials(
203+
if (StringUtils.isEmpty(envVars.get(this.awsAccessKey)) && StringUtils.isEmpty(envVars.get(this.awsSecretKey))) {
204+
aws = AWSClients.fromBasicCredentials(
204205
this.region,
205206
this.awsAccessKey,
206207
this.awsSecretKey,
207208
this.proxyHost,
208209
this.proxyPort);
210+
} else {
211+
aws = AWSClients.fromBasicCredentials(
212+
this.region,
213+
envVars.get(this.awsAccessKey),
214+
envVars.get(this.awsSecretKey),
215+
this.proxyHost,
216+
this.proxyPort);
217+
}
209218
}
210219
} else {
211220
aws = AWSClients.fromIAMRole(

src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-awsAccessKey.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<div>
22
<p>AWS Access and Secret keys to use for this deployment. At minimum the keys must be allowed to execute
3-
<code>codedeploy:*</code> and <code>s3:Put*</code>. It's a best practice to have these keys be from an IAM role
3+
<code>codedeploy:*</code> and <code>s3:Put*</code>.
4+
You can also use environment variables defined in jenkins's build for this fields.
5+
It's a best practice to have these keys be from an IAM role
46
with limited scope.</p>
57

68
<p>

src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-awsSecretKey.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<div>
22
<p>AWS Access and Secret keys to use for this deployment. At minimum the keys must be allowed to execute
3-
<code>codedeploy:*</code> and <code>s3:Put*</code>. It's a best practice to have these keys be from an IAM role
3+
<code>codedeploy:*</code> and <code>s3:Put*</code>.
4+
You can also use environment variables defined in jenkins's build for this fields.
5+
It's a best practice to have these keys be from an IAM role
46
with limited scope.</p>
57

68
<p>

0 commit comments

Comments
 (0)