Blame view

kea_testing.groovy 7.77 KB
a7a0d7905   George Vlahavas   Add initial Jenki...
1
2
3
4
5
6
7
8
9
10
  /**
  * Jenkinsfile to deploy multiple Docker containers based on docker-compose into a DEV server and run any test.
  * This pipeline will run the Docker containers, execute the tests and then stop and remove the containers from the DEV  
  * server automatically.
  **/
  
  
  pipeline {
  
    agent any
097a24e19   George Vlahavas   Fix whitespace
11
      environment {
fb793d4ad   George Vlahavas   Revert "Revert "A...
12
        
97fe60fba   George Vlahavas   Remove deployment...
13
14
15
16
17
        APP_URL = "https://kea.curex-project.eu"
        KEYCLOAK_URL = "https://keycloak-curex.gnubila.fr/auth/realms/Integration/protocol/openid-connect/token"
        USER = credentials('keycloak-test-user')
        PASSWORD = credentials('keycloak-test-password')
        CLIENT_ID = "KEA"
a7a0d7905   George Vlahavas   Add initial Jenki...
18
19
20
      }
  
    stages {
a7a0d7905   George Vlahavas   Add initial Jenki...
21
      
097a24e19   George Vlahavas   Fix whitespace
22
      stage('Run tests') {
a7a0d7905   George Vlahavas   Add initial Jenki...
23
24
        steps {
          script {
f7afd8ea9   George Vlahavas   Add a simple test
25
26
27
            echo '*************'
            echo '*** TESTS ***'
            echo '*************'
a7a0d7905   George Vlahavas   Add initial Jenki...
28
            /* Here do your tests */
f7afd8ea9   George Vlahavas   Add a simple test
29
            try {
97fe60fba   George Vlahavas   Remove deployment...
30
31
              // Get Keycloak auth token
              String token = sh(label: "get_keycloak_token", script: "curl -s -X POST $KEYCLOAK_URL -H 'Content-Type: application/x-www-form-urlencoded' -d 'username=$USER' -d 'password=$PASSWORD' -d 'grant_type=password'  -d 'client_id=$CLIENT_ID' | sed 's/.*access_token\":\"//g' | sed 's/\".*//g'", returnStdout: true)
686bf5b89   George Vlahavas   Add tests KEA_F00...
32
              String testName = "KEA_F001"
97fe60fba   George Vlahavas   Remove deployment...
33
34
              String url = "$APP_URL"
              String responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
3e893a46f   George Vlahavas   Always echo the r...
35
              echo responseCode
f7afd8ea9   George Vlahavas   Add a simple test
36
37
38
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
97fe60fba   George Vlahavas   Remove deployment...
39

55bf5645f   George Vlahavas   Move F004 and F00...
40
              testName = "KEA_F002"
97fe60fba   George Vlahavas   Remove deployment...
41
42
              url = "$APP_URL/components/od"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
3e893a46f   George Vlahavas   Always echo the r...
43
              echo responseCode
55bf5645f   George Vlahavas   Move F004 and F00...
44
45
46
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
97fe60fba   George Vlahavas   Remove deployment...
47

55bf5645f   George Vlahavas   Move F004 and F00...
48
              testName = "KEA_F003"
97fe60fba   George Vlahavas   Remove deployment...
49
50
              url = "$APP_URL/components/mltd"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
3e893a46f   George Vlahavas   Always echo the r...
51
              echo responseCode
97fe60fba   George Vlahavas   Remove deployment...
52
53
54
55
56
57
58
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
  
              testName = "KEA_F004"
              url = "$APP_URL/api/config"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
3e893a46f   George Vlahavas   Always echo the r...
59
              echo responseCode
55bf5645f   George Vlahavas   Move F004 and F00...
60
61
62
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
97fe60fba   George Vlahavas   Remove deployment...
63
64
65
66
  
              testName = "KEA_F005"
              url = "$APP_URL/api/capec"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
3e893a46f   George Vlahavas   Always echo the r...
67
              echo responseCode
97fe60fba   George Vlahavas   Remove deployment...
68
69
70
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
9396f6c4a   George Vlahavas   Move back grafana...
71
72
73
              testName = "KEA_F006"
              url = "https://kea-grafana.vlahavas.com/api/dashboards/home"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Αuthorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
3e893a46f   George Vlahavas   Always echo the r...
74
              echo responseCode
cfd27a3cb   George Vlahavas   Add back all tests
75
76
77
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
97fe60fba   George Vlahavas   Remove deployment...
78

9396f6c4a   George Vlahavas   Move back grafana...
79
80
              testName = "KEA_F007"
              url = "https://kea-kibana.vlahavas.com/app/kibana"
97fe60fba   George Vlahavas   Remove deployment...
81
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
3e893a46f   George Vlahavas   Always echo the r...
82
              echo responseCode
cfd27a3cb   George Vlahavas   Add back all tests
83
84
85
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
97fe60fba   George Vlahavas   Remove deployment...
86

9396f6c4a   George Vlahavas   Move back grafana...
87
88
              testName = "KEA_F008"
              url = "$APP_URL/components/ceptd"
97fe60fba   George Vlahavas   Remove deployment...
89
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
3e893a46f   George Vlahavas   Always echo the r...
90
              echo responseCode
a440995cf   George Vlahavas   Move KEA_F003 to ...
91
92
93
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
97fe60fba   George Vlahavas   Remove deployment...
94

296ef6417   George Vlahavas   Add OD test
95
96
              testName = "KEA_F009"
              url = "$APP_URL/api/v1/od/start"
7ebc5964e   George Vlahavas   Don't fetch only ...
97
              responseCode = sh(label: testName, script: "curl -m 10 -sL -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url", returnStdout: true)
1504b1017   George Vlahavas   Add echo
98
              echo responseCode
296ef6417   George Vlahavas   Add OD test
99
100
101
102
103
104
              if (!responseCode.endsWith('200')) {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
              String processId = responseCode.split(",")[1].split(":")[1].split('"')[1];
              url = "$APP_URL/api/v1/od/status"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
3e893a46f   George Vlahavas   Always echo the r...
105
              echo responseCode
296ef6417   George Vlahavas   Add OD test
106
107
108
109
110
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
              url = "$APP_URL/api/v1/od/stop/$processId"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
3e893a46f   George Vlahavas   Always echo the r...
111
              echo responseCode
296ef6417   George Vlahavas   Add OD test
112
113
114
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
88b814847   George Vlahavas   Add MLTD tests
115
116
117
118
119
120
121
122
              
              testName = "KEA_F010"
              url = "$APP_URL/api/v1/mltd/start"
              responseCode = sh(label: testName, script: "curl -m 10 -sL -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url", returnStdout: true)
              echo responseCode
              if (!responseCode.endsWith('200')) {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
6ab7eb8ad   George Vlahavas   Reuse variable
123
              processId = responseCode.split(",")[1].split(":")[1].split('"')[1];
88b814847   George Vlahavas   Add MLTD tests
124
125
126
127
128
129
130
131
132
133
134
135
              url = "$APP_URL/api/v1/mltd/status"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
              echo responseCode
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
              url = "$APP_URL/api/v1/mltd/stop/$processId"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
              echo responseCode
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
296ef6417   George Vlahavas   Add OD test
136

f7afd8ea9   George Vlahavas   Add a simple test
137
138
139
140
            } catch (ignored) {
              currentBuild.result = 'FAILURE'
              echo "KEA Deployment Tests failed"
            }
a7a0d7905   George Vlahavas   Add initial Jenki...
141
142
143
          }
        }
      }
a7a0d7905   George Vlahavas   Add initial Jenki...
144
145
    }
  }
097a24e19   George Vlahavas   Fix whitespace
146