forked from tekdi/pratham-saral-school-prepareness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-deploy
41 lines (34 loc) · 1.24 KB
/
Jenkinsfile-deploy
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
#!groovy
node('saral-poc') {
try {
stage('Checkout'){
checkout scm
}
stage('Docker-compose')
withCredentials([usernamePassword(credentialsId: 'anuvaad-docker-hub-credentials', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
sh '''
environment=$(echo "$JOB_BASE_NAME" | rev | cut -d'-' -f 1 | rev)
compose_file=$(echo "$image_name")
tag=$(echo "$image_tag")
sudo docker service rm saralpoc_$compose_file
sudo env image="$compose_file" tag=$tag env="$environment" docker stack deploy --compose-file=$compose_file.yml --with-registry-auth --resolve-image=always saralpoc
sudo docker service update saralpoc_gateway --force
echo "Reload Saral Reference Data ? : $reloadSaralReferenceData"
if [ $reloadSaralReferenceData = true ]
then
echo "sleeping for 30s for containers to start"
sleep 30s
sudo docker exec $(sudo docker ps -aqf "name=^saralpoc_saral-backend") node ./data/import-data.js --delete
sudo docker exec $(sudo docker ps -aqf "name=^saralpoc_saral-backend") node ./data/import-data.js --import
echo 'Reloaded Saral Reference Data'
else
echo 'skipping Reload Saral Reference Data'
fi
'''
}
}
catch (err) {
currentBuild.result = "FAILURE"
throw err
}
}