This repository has been archived by the owner on Jan 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathJenkinsfile-example
114 lines (96 loc) · 2.95 KB
/
Jenkinsfile-example
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!groovy
//
// Example Jenkinsfile, slightly modified from working code.
// Probably not usable in current state, lacking library amongst other elements.
// Saved for reference.
//
// This Jenkinsfile was run on a PR, it doesn't build environments.
//
def channel = '#devops-builds'
def product = 'management'
properties(
[[$class: 'GithubProjectProperty', projectUrlStr: 'https://github.com/hmcts/ansible-generated-terraform/'],
pipelineTriggers([[$class: 'GitHubPushTrigger']])]
)
@Library('Reform') _
node {
ws('ansible-generated-terraform') { // This must be the name of the role otherwise ansible won't find the role
try {
wrap([$class: 'AnsiColorBuildWrapper', colorMapName: 'xterm']) {
stage('Checkout') {
checkout scm
}
stage('Start containers') {
dir ('main-environment') {
sh 'molecule create'
}
}
stage('if else check') {
script {
if (product.equals('management')) {
sh """
echo "Your product is set to management"
"""
} else {
sh """
echo "Your product is unset."
"""
}
}
}
stage('Run tests') {
dir ('main-environment') {
sh '''
molecule syntax
molecule verify
'''
}
}
stage('Run role') {
dir ('main-environment') {
sh 'molecule converge'
}
}
// stage('Check idempotent') {
// dir ('main-environment') {
// sh 'molecule idempotence'
// }
// }
withCredentials([
[$class: 'StringBinding', credentialsId: 'IDAM_ARM_CLIENT_SECRET', variable: 'ARM_CLIENT_SECRET'],
[$class: 'StringBinding', credentialsId: 'IDAM_ARM_CLIENT_ID', variable: 'ARM_CLIENT_ID'],
[$class: 'StringBinding', credentialsId: 'IDAM_ARM_TENANT_ID', variable: 'ARM_TENANT_ID'],
[$class: 'StringBinding', credentialsId: 'IDAM_ARM_SUBSCRIPTION_ID', variable: 'ARM_SUBSCRIPTION_ID']
]) {
stage('TF init and plan for main-environment') {
sh '''
# otherwise ansible-generated stays owned by root
sudo chown -R jenkins main-environment/ansible-generated
find
for dir in \$(find main-environment/ansible-generated/*/*/* -type d); do
cd \$dir
terraform version
terraform init -lock=false
terraform plan -lock=false
cd -
done
'''
}
}
}
} catch (err) {
notifyBuildFailure channel: "${channel}"
throw err
} finally {
stage('Cleanup') {
dir ('main-environment') {
sh '''
sudo chown -R jenkins ansible-generated
molecule destroy
'''
}
deleteDir()
}
}
}
}