diff --git a/Jenkinsfile b/Jenkinsfile index 3a7ef41..f18e689 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -44,17 +44,53 @@ pipeline { def json = """ {"username": "${PORTAINER_CREDENTIALS_USR}", "password": "${PORTAINER_CREDENTIALS_PSW}"} """ - def jwtResponse = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON', validResponseCodes: '200', httpMode: 'POST', ignoreSslErrors: true, consoleLogResponseBody: true, requestBody: json, url: "http://192.168.4.8:9000/api/auth" + def jwtResponse = httpRequest + acceptType: 'APPLICATION_JSON', + contentType: 'APPLICATION_JSON', + validResponseCodes: '200', + httpMode: 'POST', + ignoreSslErrors: true, + consoleLogResponseBody: true, + requestBody: json, + url: "http://192.168.4.8:9000/api/auth" def jwtObject = new groovy.json.JsonSlurper().parseText(jwtResponse.getContent()) env.JWTTOKEN = "Bearer ${jwtObject.jwt}" } + echo "Authenticated" script { def json = """ """ - def response = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON', validResponseCodes: '200', httpMode: 'POST', ignoreSslErrors: true, consoleLogResponseBody: true, requestBody: json, customHeaders: [["name": "Authorization", "value": "${env.JWTTOKEN}"]], url: "http://192.168.4.8:9000/api/endpoints/26/docker/containers/145772505f27bcdef1fbd807ecbb7b4ccbe6fb86dbb3a2bd0e22951557a15a10/stop" + def response = httpRequest + acceptType: 'APPLICATION_JSON', + contentType: 'APPLICATION_JSON', + validResponseCodes: '204', + httpMode: 'POST', + ignoreSslErrors: true, + consoleLogResponseBody: true, + requestBody: json, + customHeaders: [["name": "Authorization", "value": "${env.JWTTOKEN}"]], + url: "http://192.168.4.8:9000/api/endpoints/26/docker/containers/145772505f27bcdef1fbd807ecbb7b4ccbe6fb86dbb3a2bd0e22951557a15a10/stop" new groovy.json.JsonSlurper().parseText(jwtResponse.getContent()) } + echo "Stopping Container" + script { + def json = """ + + """ + def response = httpRequest + acceptType: 'APPLICATION_JSON', + contentType: 'APPLICATION_JSON', + validResponseCodes: '204', + httpMode: 'POST', + ignoreSslErrors: true, + consoleLogResponseBody: true, + requestBody: json, + customHeaders: [["name": "Authorization", "value": "${env.JWTTOKEN}"]], + url: "http://192.168.4.8:9000/api/endpoints/26/docker/containers/145772505f27bcdef1fbd807ecbb7b4ccbe6fb86dbb3a2bd0e22951557a15a10/start" + new groovy.json.JsonSlurper().parseText(jwtResponse.getContent()) + } + echo "Starting Container" } } }