Blame view

kea_testing.groovy 4.75 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
        
2daaa5ddc   George Vlahavas   Update some tests
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 */
21b0aad19   George Vlahavas   Wait a bit more
29
            sleep 90
f7afd8ea9   George Vlahavas   Add a simple test
30
            try {
2daaa5ddc   George Vlahavas   Update some tests
31
32
              // 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...
33
              String testName = "KEA_F001"
2daaa5ddc   George Vlahavas   Update some tests
34
35
              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)
f7afd8ea9   George Vlahavas   Add a simple test
36
37
38
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
2daaa5ddc   George Vlahavas   Update some tests
39

55bf5645f   George Vlahavas   Move F004 and F00...
40
              testName = "KEA_F002"
2daaa5ddc   George Vlahavas   Update some tests
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)
55bf5645f   George Vlahavas   Move F004 and F00...
43
44
45
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
2daaa5ddc   George Vlahavas   Update some tests
46

55bf5645f   George Vlahavas   Move F004 and F00...
47
              testName = "KEA_F003"
2daaa5ddc   George Vlahavas   Update some tests
48
49
50
51
52
53
54
55
56
              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)
              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)
55bf5645f   George Vlahavas   Move F004 and F00...
57
58
59
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
2daaa5ddc   George Vlahavas   Update some tests
60
61
62
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)
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
cfd27a3cb   George Vlahavas   Add back all tests
67
              testName = "KEA_F006"
2daaa5ddc   George Vlahavas   Update some tests
68
69
              url = "https://kea-grafana.vlahavas.com"
              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)
cfd27a3cb   George Vlahavas   Add back all tests
70
71
72
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
2daaa5ddc   George Vlahavas   Update some tests
73

cfd27a3cb   George Vlahavas   Add back all tests
74
              testName = "KEA_F007"
2daaa5ddc   George Vlahavas   Update some tests
75
76
              url = "https://kea-kibana.vlahavas.com/app/kibana"
              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)
cfd27a3cb   George Vlahavas   Add back all tests
77
78
79
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
2daaa5ddc   George Vlahavas   Update some tests
80

cfd27a3cb   George Vlahavas   Add back all tests
81
              testName = "KEA_F008"
2daaa5ddc   George Vlahavas   Update some tests
82
83
              url = "$APP_URL/components/ceptd"
              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)
a440995cf   George Vlahavas   Move KEA_F003 to ...
84
85
86
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
2daaa5ddc   George Vlahavas   Update some tests
87

f7afd8ea9   George Vlahavas   Add a simple test
88
89
90
91
            } catch (ignored) {
              currentBuild.result = 'FAILURE'
              echo "KEA Deployment Tests failed"
            }
a7a0d7905   George Vlahavas   Add initial Jenki...
92
93
94
          }
        }
      }
a7a0d7905   George Vlahavas   Add initial Jenki...
95
96
    }
  }
097a24e19   George Vlahavas   Fix whitespace
97