forked from GoogleCloudPlatform/cloud-foundation-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
47 lines (42 loc) · 1.56 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
#!/usr/bin/env groovy
// requires "Pipeline Utility Steps" plugin
// requires "pipeline-vars" file to be setup inside jenkins user home dir
def config_dir = "pipeline/project" // relative to ${cft_dir}
def env = "~/pipeline-vars"
def repo = "https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit"
def branch = "pipeline"
def git_dir = "cft"
def cft_dir = "dm"
pipeline {
agent any
stages {
stage('Checkout Repos') {
steps {
sh "rm -rf ${git_dir}"
sh "git clone ${repo} ${git_dir}"
sh "cd ${git_dir} && git checkout ${branch}"
}
}
stage('Initialize Deploy Stages') {
steps {
sh ". ${env} && cd ${git_dir}/${cft_dir} && cft apply ${config_dir} --show-stages --format yaml> .stages.yaml"
script {
def graph = readYaml file: "${git_dir}/${cft_dir}/.stages.yaml"
def i = 1
graph.each { stg ->
stage("stage-${i}") {
def config_list = []
stg.each { conf ->
config_list.add(conf.source)
}
def configs = config_list.join(" ")
echo "Executing configs: ${configs}"
sh ". ${env} && cd ${git_dir}/${cft_dir} && cft apply ${configs}"
}
i++
}
}
}
}
}
}