-
Notifications
You must be signed in to change notification settings - Fork 5
/
WithAwsPlugin.groovy
36 lines (31 loc) · 1.08 KB
/
WithAwsPlugin.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class WithAwsPlugin implements Plugin {
public static init() {
StagePlugins.add(new WithAwsPlugin(), DeployStage)
}
public void apply(Stage stage) {
def environment = stage.getEnvironment()
stage.decorate(withAwsClosure(environment))
}
public Map getOptions(String environment, EnvironmentUtil util) {
def results = [:]
def role = null
role = util.getEnvironmentVariable("${environment.toUpperCase()}_AWS_ROLE_ARN".toString())
if (role != null) {
results['role'] = role
} else {
role = util.getEnvironmentVariable('AWS_ROLE_ARN')
if (role != null) {
results['role'] = role
}
}
return results
}
public Closure withAwsClosure(String environment) {
return { innerClosure ->
def envUtil = new EnvironmentUtil(delegate)
def options = getOptions(environment, envUtil)
sh "echo \"WithAwsPlugin.withAWS(${options}) for ${environment}\""
withAWS(options, innerClosure)
}
}
}