/** * 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 environment { // 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 stash excludes: "CEPTD,MLTD,OD,elk_base.tar.gz", name: 'kea-api' } } stage('Deploy Docker containers in DEV server') { steps { unstash name: 'kea-api' script { docker.withServer("$DEPLOYMENT_HOST", "$DEPLOYMENT_HOST_CREDENTIALS") { docker.withRegistry("$PRIVATE_REGISTRY" , 'artifactory') { sh 'hostname;pwd;ls -lR' echo 'Deploying the specified Docker containers in DEV server' sh 'sh deploy.sh' } } } } } stage('Run tests') { steps { script { echo '*************' echo '*** TESTS ***' echo '*************' /* Here do your tests */ 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" } } } } stage('Stop and remove the Docker containers in DEV server') { 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' } } } } } } }