-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.build
202 lines (176 loc) · 7.41 KB
/
Jenkinsfile.build
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
@Library ('folio_jenkins_shared_libs') _
/*
* parameters {
* choice(
* name: 'PLATFORM',
* defaultValue: 'platform-complete',
* description: 'Platform repo in https://github.com/folio-org/'
* )
* }
*/
pipeline {
environment {
BRANCH = "${GIT_BRANCH.split("/")[1]}"
OKAPI_TENANT = 'diku'
SLACK_CHANNEL = '#hosted-reference-envs'
ANSIBLE_CONFIG = "${env.WORKSPACE}/folio-infrastructure/CI/ansible/ansible.cfg"
DOCKERHUB_CI_PULL = credentials('dockerhub-ci-pull-account')
DOCKER_REGISTRIES = credentials('okapi-docker-registries-pull-json')
folioRegistry = 'https://folio-registry.dev.folio.org'
}
options {
timeout(60)
buildDiscarder(logRotator(numToKeepStr: '30'))
}
agent {
node {
label 'platform-build'
}
}
stages {
stage('Setup') {
steps {
sendNotifications 'STARTED'
echo 'On branch: ' + env.BRANCH
script {
currentBuild.displayName = "#${env.BUILD_NUMBER}-${env.JOB_BASE_NAME}"
if (params.PLATFORM == 'platform-core') {
env.folio_config = 'snapshot-core'
env.ec2_instanceType = 'm5.xlarge'
env.ec2_group = 'build_snapshot_core'
}
else {
env.folio_config = 'snapshot'
env.ec2_instanceType = 'm5.2xlarge'
env.ec2_group = 'build_snapshot'
}
}
}
}
stage('Build Stripes Platform') {
steps {
// the tenant and okapi url are irrelevant here.
buildStripesPlatform("https://dummy-name-okapi.dev.folio.org", env.OKAPI_TENANT)
}
}
stage('Check Interface Dependencies') {
steps {
script {
echo "Creating okapi preseed module list."
sh 'jq -s \'.[0]=([.[]]|flatten)|.[0]\' stripes-install.json install-extras.json > install-pre.json'
def installPreJson = readFile('./install-pre.json')
platformDepCheck('diku',installPreJson)
echo 'Generating backend dependency list to okapi-install.json'
sh 'jq \'map(select(.id | test(\"mod-\"; \"i\")))\' install.json > okapi-install.json'
sh 'cat okapi-install.json'
echo "Append edge modules to final stripes-install.json."
sh 'mv stripes-install.json stripes-install-pre.json'
sh 'jq \'map(select(.id | test(\"edge-\"; \"i\")))\' install.json > install-edge.json'
sh 'jq -s \'.[0]=([.[]]|flatten)|.[0]\' stripes-install-pre.json install-edge.json > stripes-install.json'
sh 'cat stripes-install.json'
}
}
}
stage('Build FOLIO instance') {
steps {
checkout([$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: false,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: true],
[$class: 'RelativeTargetDirectory', relativeTargetDir: 'folio-infrastructure']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'id-jenkins-github-personal-token-with-username',
url: 'https://github.com/folio-org/folio-infrastructure']]
])
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
credentialsId: 'jenkins-aws',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
dir("${env.WORKSPACE}/folio-infrastructure") {
logFileFilter {
ansiblePlaybook(credentialsId: '11657186-f4d4-4099-ab72-2a32e023cced',
disableHostKeyChecking: true,
installation: 'Ansible',
inventory: 'CI/ansible/inventory',
playbook: "CI/ansible/build-snapshot-platform.yml",
sudoUser: null,
vaultCredentialsId: 'ansible-vault-pass',
extraVars: [ec2_group: "${env.ec2_group}",
instance_type: "${env.ec2_instanceType}",
build_module_list_files: "${env.WORKSPACE}",
folio_config: "${env.folio_config}" ],
extras: "-e \"{\\\"docker_image_repo\\\":{\\\"username\\\":\\\"${env.DOCKERHUB_CI_PULL_USR}\\\",\\\"password\\\":\\\"${env.DOCKERHUB_CI_PULL_PSW}\\\"}}\"")
}
}
}
}
}
// If stripes build is successful, update yarn.lock and commit
stage('Update Branch Install Artifacts') {
steps {
script {
dir("$env.WORKSPACE") {
def installFiles = ['stripes-install.json',
'okapi-install.json',
'install.json',
'yarn.lock']
sh "git checkout $env.BRANCH"
sh 'git add yarn.lock'
for (int i = 0; i < installFiles.size(); i++) {
sh "git add ${env.WORKSPACE}/${installFiles[i]}"
}
def commitStatus = sh(returnStatus: true,
script: 'git commit -m "[CI SKIP] Updating install files"')
if ( commitStatus == 0 ) {
sshGitPush(origin: params.PLATFORM, branch: env.BRANCH)
}
else {
echo "No changes to artifacts"
}
}
}
}
}
} // end stages
post {
failure {
slackSend channel: "$env.SLACK_CHANNEL",
message: "Failure: ${env.JOB_NAME} ${env.BUILD_DISPLAY_NAME} (<${env.BUILD_URL}|Open>)"
// publish the Okapi on failure.
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
credentialsId: 'jenkins-aws',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
script {
// find ec2 instance
def sshIp = sh (returnStdout: true, script:"aws --region us-east-1 ec2 describe-instances --filters 'Name=tag:Group,Values=${env.ec2_group}' --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text").trim()
publishOkapiLog(sshIp)
}
}
}
always {
sendNotifications currentBuild.result
}
cleanup {
echo "Sleeping during cleanup to enable ansible error reporting."
sleep 10
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
credentialsId: 'jenkins-aws',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
script {
def instance = sh(returnStdout: true, script: "aws --region us-east-1 --output text ec2 describe-instances --filters 'Name=tag:Group,Values=${env.ec2_group}' 'Name=instance-state-name,Values=running' --query 'Reservations[*].Instances[*].[InstanceId]'")
if (instance) {
echo "Terminating instance: $instance"
sh "aws --region us-east-1 --output text ec2 terminate-instances --instance-ids $instance"
}
}
}
}
}
}