-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
84 lines (70 loc) · 2.49 KB
/
Jenkinsfile
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
library(
identifier: '[email protected]',
retriever: modernSCM([$class: 'GitSCMSource',
remote: 'https://github.com/SmartColumbusOS/pipeline-lib',
credentialsId: 'jenkins-github-user'])
)
properties(
[
disableConcurrentBuilds(),
parameters([
booleanParam(
name: 'skipBuild',
defaultValue: true,
description: 'Leave true to generate parameters for production releases without executing the entire job.'),
text(
name: 'environmentsParameter',
defaultValue: scos.environments().join("\n"),
description: 'Environments in which to deploy common/env')
])
]
)
def environments = params.environmentsParameter.trim().split("\n").collect { environment ->
environment.trim()
}
def terraformOverrides = params.findAll { key, value ->
key != "environmentsParameter" && key != "skipBuild" && value != ""
}
node('infrastructure') { ansiColor('xterm') { sshagent(["GitHub"]) { withCredentials([
[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: 'aws_jenkins_user',
variable: 'AWS_ACCESS_KEY_ID'
]
]) {
if(params.skipBuild && scos.changeset.isRelease) {
currentBuild.result = 'ABORTED'
error('Build skipped per "skipBuild" parameter.')
}
scos.doCheckoutStage()
environments.each { environment ->
def terraform = scos.terraform(environment)
def isGoingToProd = (scos.changeset.isRelease && environment == 'prod')
def shouldBePlanned = (!scos.changeset.isRelease || isGoingToProd)
if(shouldBePlanned) {
doPlan(terraform, environment, terraformOverrides)
}
if (scos.changeset.shouldDeploy(environment)) {
if (isGoingToProd) {
timeout(10) {
input('Apply infrastructure changes?')
}
}
stage("Deploy ${environment}") {
terraform.apply()
}
stage('Tag') {
scos.applyAndPushGitHubTag(environment)
}
}
}
}}}}
def doPlan(terraform, environment, terraformOverrides) {
stage("Plan ${environment}") {
terraform.init()
def overrides = [:]
overrides << terraformOverrides
terraform.plan(terraform.defaultVarFile, overrides)
archiveArtifacts artifacts: 'plan-*.txt', allowEmptyArchive: false
}
}