-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
70 lines (55 loc) · 1.95 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
library(
identifier: 'pipeline-lib@4.8.0',
retriever: modernSCM([$class: 'GitSCMSource',
remote: 'https://github.com/SmartColumbusOS/pipeline-lib',
credentialsId: 'jenkins-github-user'])
)
properties([
pipelineTriggers([scos.dailyBuildTrigger()]),
])
def image
def doStageIf = scos.&doStageIf
def doStageIfRelease = doStageIf.curry(scos.changeset.isRelease)
def doStageUnlessRelease = doStageIf.curry(!scos.changeset.isRelease)
def doStageIfPromoted = doStageIf.curry(scos.changeset.isMaster)
node ('infrastructure') {
ansiColor('xterm') {
scos.doCheckoutStage()
doStageUnlessRelease('Build') {
image = docker.build("scos/lime-survey:${env.GIT_COMMIT_HASH}")
}
doStageUnlessRelease('Deploy to Dev') {
scos.withDockerRegistry {
image.push()
image.push('latest')
}
deployTo(environment: 'dev')
}
doStageIfPromoted('Deploy to Staging') {
def environment = 'staging'
deployTo(environment: environment)
scos.applyAndPushGitHubTag(environment)
scos.withDockerRegistry {
image.push(environment)
}
}
doStageIfRelease('Deploy to Production') {
def releaseTag = env.BRANCH_NAME
def promotionTag = 'prod'
deployTo(environment: 'prod', internal: false)
scos.applyAndPushGitHubTag(promotionTag)
scos.withDockerRegistry {
image = scos.pullImageFromDockerRegistry("scos/lime-survey", env.GIT_COMMIT_HASH)
image.push(releaseTag)
image.push(promotionTag)
}
}
}
}
def deployTo(params = [:]) {
def environment = params.get('environment')
def terraform = scos.terraform(environment)
terraform.init()
terraform.plan(terraform.defaultVarFile)
terraform.apply()
}