-
Notifications
You must be signed in to change notification settings - Fork 3
/
jenkinsfile
95 lines (82 loc) · 3.12 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
pipeline {
triggers {
githubPush()
}
agent any
tools {
nodejs "Node"
maven 'maven-3.6.3'
}
environment {
CI = 'true'
CURR_DIR = pwd()
API_DIR = '/UserAPI'
DEV_ENV = 'dev'
PROD_ENV = 'prod'
TEST_SCRIPT_FILE = 'test_script.postman_collection.json'
INTEGRATION_DIR = '/UserDataIntegration'
dev_ei_host='dev.ei.com'
prod_ei_host='dev.ei.com'
dev_user_be='dev.be.com'
prod_user_be='prod.be.com'
}
stages {
stage('Preparation') {
steps{
sh '''
echo "PATH = ${PATH}"
echo "M2_HOME = ${M2_HOME}"
'''
git branch: "master",
url: 'https://github.com/dushansachinda/wso2_apim_cicd.git',
credentialsId: 'demo-github-cred'
}
}
stage('Deploy to UAT') {
environment{
RETRY = '80'
}
steps {
echo 'Build project -Dev $DEV_ENV'
dir("UserDataIntegration"){
sh 'mvn clean install -Dmaven.test.skip -Dei.host=$dev_ei_host -Dbe.host=$dev_user_be'
}
echo 'Deploying EI project -Dev $DEV_ENV'
dir("UserDataIntegration/UserDataIntegrationCompositeExporter"){
sh 'mvn clean deploy -Dmaven.deploy.skip=true -Dmaven.car.deploy.skip=false -Dei.host=$dev_ei_host -Dbe.host=$dev_user_be'
}
waitForDeployment()
echo 'Logging into $DEV_ENV'
withCredentials([usernamePassword(credentialsId: 'dev_apim_admin', usernameVariable: 'DEV_USERNAME', passwordVariable: 'DEV_PASSWORD')]) {
sh 'apictl login $DEV_ENV -u $DEV_USERNAME -p $DEV_PASSWORD -k'
}
echo 'Deploying to $DEV_ENV'
sh 'apictl import-api -f $CURR_DIR$API_DIR -e $DEV_ENV -k --preserve-provider --update --verbose'
}
}
stage('Run Tests') {
steps {
echo 'Running tests in $DEV_ENV'
sh 'newman run $CURR_DIR/$TEST_SCRIPT_FILE --insecure'
}
}
stage('Deploy to Production') {
environment{
RETRY = '60'
}
steps {
sh 'echo "Logging into $PROD_ENV"'
withCredentials([usernamePassword(credentialsId: 'prod_apim_admin', usernameVariable: 'PROD_USERNAME', passwordVariable: 'PROD_PASSWORD')]) {
sh 'apictl login $PROD_ENV -u $PROD_USERNAME -p $PROD_PASSWORD -k'
}
echo 'Deploying to Production'
sh 'apictl import-api -f $CURR_DIR$API_DIR -e $PROD_ENV -k --preserve-provider --update --verbose'
}
}
}
}
def waitForDeployment() {
echo "Sleeping start... 10seconds."
sleep(10)
echo "Sleeping ends"
}