-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsFile
109 lines (97 loc) · 3.68 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
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
pipeline {
agent {
node {
label 'master'
}
}
triggers {
GenericTrigger(
genericVariables: [
[ key: 'name', value: '$.data.name' ],
[ key: 'location', value: '$.data.path' ]
],
token: '123',
printContributedVariables: true,
printPostContent: true,
)
}
options {
buildDiscarder logRotator(
daysToKeepStr: '16',
numToKeepStr: '10'
)
}
tools {nodejs "Node"}
stages {
stage('Setup Environment for APICTL') {
steps {
sh '''#!/bin/bash
# Set source repo path
apictl set --vcs-source-repo-path /var/lib/jenkins/workspace/CICD-Dev_dev
# Set deployment repo path
apictl set --vcs-deployment-repo-path /var/lib/jenkins/workspace/CICD-Deploy_main
envs=$(apictl get envs --format "{{.Name}}")
if [ -z "$envs" ];
then
echo "No environments configured. Setting the dev and prod environments.."
apictl add env dev --apim https://${APIM_HOST}:9443 -k
apictl add env prod --apim https://${APIM_HOST}:9444 -k
else
echo "Environments :"$envs
if [[ $envs != *"dev"* ]]; then
echo "Dev environment is not configured. Setting the dev environment.."
apictl add env dev --apim https://${APIM_DEV_HOST}:9443 -k
fi
if [[ $envs != *"prod"* ]]; then
echo "Prod environment is not configured. Setting the prod environment.."
apictl add env prod --apim https://${APIM_HOST}:9444 -k
fi
fi
'''
}
}
stage('Deploy artifacts to dev environment') {
steps {
sh '''#!/bin/bash
# Download the artifacts from the artifactory
cd /var/lib/jenkins/.wso2apictl/exported/apis
wget https://${ARTIFACTORY_HOST}/artifactory/${ARTIFACTORY_REPO}/$location
# Login to the dev environment
apictl login dev -u admin -p admin -k
# Deploy artifacts to dev environment
apictl vcs deploy -e dev -k
# Wait for deployment before running tests
sleep 6
'''
}
}
stage('Run tests') {
steps {
sh '''#!/bin/bash
testfiles=\$(find /var/lib/jenkins/workspace/CICD-Dev_dev/tests -iname "*.sh")
for i in \$testfiles ; do bash \$i; done
'''
}
}
stage('Deploy artifacts to prod environment') {
steps {
sh '''
# Login to the prod environment
apictl login prod -u admin -p admin -k
# Deploy artifacts to prod environment
apictl vcs deploy -e prod -k
'''
}
}
}
post {
always {
sh '''
# Logout from the dev environment
apictl logout dev -k
# Logout from the prod environment
apictl logout prod -k
'''
}
}
}