Blame view

kea_testing.groovy 2.36 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 {
a7a0d7905   George Vlahavas   Add initial Jenki...
12
13
14
15
16
17
18
19
20
21
22
23
24
25
        // Keep as is the following two lines
        PRIVATE_REGISTRY = "https://registry.curex-project.eu:443/curex-local/"
        ARTIFACTORY_URL = "registry.curex-project.eu:443/curex-local/"
  
        DEPLOYMENT_HOST = "116.203.166.220:2376"
        DEPLOYMENT_HOST_CREDENTIALS = "vm2-creds"
      }
  
    stages {
             
      stage('Checkout the source code') {
        steps {
          checkout scm
        }
2ccd14e9d   George Vlahavas   Try stash/unstash
26
        stash 'kea-stash'
a7a0d7905   George Vlahavas   Add initial Jenki...
27
28
29
30
31
      }
      
    
      stage('Deploy Docker containers in DEV server') {
        steps {
2ccd14e9d   George Vlahavas   Try stash/unstash
32
          unstash 'kea-stash'
a7a0d7905   George Vlahavas   Add initial Jenki...
33
34
35
          script {
            docker.withServer("$DEPLOYMENT_HOST", "$DEPLOYMENT_HOST_CREDENTIALS") {
              docker.withRegistry("$PRIVATE_REGISTRY" , 'artifactory') {
6eb1478eb   George Vlahavas   Revert "Add reuse...
36

a7a0d7905   George Vlahavas   Add initial Jenki...
37
38
                echo 'Deploying the specified Docker containers in DEV server'
                sh 'sh deploy.sh'
a7a0d7905   George Vlahavas   Add initial Jenki...
39
40
41
42
43
              }
            }
          }
        }
      }
097a24e19   George Vlahavas   Fix whitespace
44
45
  
      stage('Run tests') {
a7a0d7905   George Vlahavas   Add initial Jenki...
46
47
        steps {
          script {
f7afd8ea9   George Vlahavas   Add a simple test
48
49
50
            echo '*************'
            echo '*** TESTS ***'
            echo '*************'
a7a0d7905   George Vlahavas   Add initial Jenki...
51
            /* Here do your tests */
f7afd8ea9   George Vlahavas   Add a simple test
52
53
54
55
56
57
58
59
60
61
62
63
            sleep 50
            try {
              String testName = "1. Check that app is running - 200 response code"
              String url = "http://kea.curex-project.eu/"
              String responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true)
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
            } catch (ignored) {
              currentBuild.result = 'FAILURE'
              echo "KEA Deployment Tests failed"
            }
a7a0d7905   George Vlahavas   Add initial Jenki...
64
65
66
          }
        }
      }
097a24e19   George Vlahavas   Fix whitespace
67
      stage('Stop and remove the Docker containers in DEV server') {
a7a0d7905   George Vlahavas   Add initial Jenki...
68
69
70
71
72
73
74
75
76
77
78
79
80
        steps {
          script {
            docker.withServer("$DEPLOYMENT_HOST", "$DEPLOYMENT_HOST_CREDENTIALS") {
              docker.withRegistry("$PRIVATE_REGISTRY" , 'artifactory') {
  
                echo 'Stop and remove the specified Docker containers from the DEV server'
                sh 'sh delete.sh'
              
              }
            }
          }
        }
      }
a7a0d7905   George Vlahavas   Add initial Jenki...
81
82
    }
  }
097a24e19   George Vlahavas   Fix whitespace
83