diff --git a/openvidu-test-e2e/jenkins/Jenkinsfile b/openvidu-test-e2e/jenkins/Jenkinsfile index bac526d7..d122c7f6 100644 --- a/openvidu-test-e2e/jenkins/Jenkinsfile +++ b/openvidu-test-e2e/jenkins/Jenkinsfile @@ -165,6 +165,7 @@ node('container') { currentBuild.result = 'FAILURE' } finally { environmentStop() + commonFunctions.removeStrandedContainers() } } } diff --git a/openvidu-test-e2e/jenkins/commonFunctions.groovy b/openvidu-test-e2e/jenkins/commonFunctions.groovy index 82ae14ef..dd92ab29 100644 --- a/openvidu-test-e2e/jenkins/commonFunctions.groovy +++ b/openvidu-test-e2e/jenkins/commonFunctions.groovy @@ -21,30 +21,7 @@ def prepareTestingEnvironment() { sh 'sudo rm -rf /opt/openvidu-cache/.m2/repository/org/kurento || true' }, 'Removing stranded containers': { - sh(script: """#!/bin/bash -xe - declare -a arr=("openvidu/openvidu-test-e2e:" - "openvidu/openvidu-pro-test-e2e:" - "selenium/standalone-chrome:" - "selenium/standalone-firefox:" - "selenium/standalone-opera:" - "openvidu/mediasoup-controller:" - "openvidu/openvidu-server-pro:" - "openvidu/openvidu-redis:" - "openvidu/openvidu-coturn:" - "openvidu/openvidu-proxy:" - "openvidu/replication-manager:" - "docker.elastic.co/elasticsearch/elasticsearch:" - "docker.elastic.co/kibana/kibana:" - "docker.elastic.co/beats/metricbeat-oss:" - "docker.elastic.co/beats/filebeat-oss:" - "openvidu/openvidu-pro-dind-media-node:" - "kurento/kurento-media-server:" - "openvidu/media-node-controller:") - for image in "${arr[@]}" - do - docker ps -a | awk '{ print $1,$2 }' | grep "${image}" | awk '{ print $1 }' | xargs -I {} docker rm -f {} - done - """.stripIndent()) + removeStrandedContainers() } ) @@ -61,13 +38,13 @@ def prepareTestingEnvironment() { } }, 'Pull selenium/standalone-chrome': { - docker.image("selenium/standalone-chrome:latest").pull() + docker.image('selenium/standalone-chrome:latest').pull() }, 'Pull selenium/standalone-firefox': { - docker.image("selenium/standalone-firefox:latest").pull() + docker.image('selenium/standalone-firefox:latest').pull() }, 'Pull selenium/standalone-opera': { - docker.image("selenium/standalone-opera:latest").pull() + docker.image('selenium/standalone-opera:latest').pull() }, 'Pull openvidu/mediasoup-controller': { if (env.MEDIASOUP_CONTROLLER_VERSION) { @@ -80,7 +57,7 @@ def prepareTestingEnvironment() { } }, 'Download fake video': { - sh(script: """#!/bin/bash -xe + sh(script: '''#!/bin/bash -xe FAKE_VIDEO=/opt/openvidu-cache/barcode.y4m if [ ! -f ${FAKE_VIDEO} ]; then sudo curl --location https://github.com/OpenVidu/openvidu/raw/master/openvidu-test-e2e/docker/barcode.y4m --create-dirs --output /opt/openvidu-cache/barcode.y4m @@ -88,10 +65,10 @@ def prepareTestingEnvironment() { echo "File ${FAKE_VIDEO} already exists" fi sudo cp /opt/openvidu-cache/barcode.y4m /opt/openvidu/barcode.y4m - """.stripIndent()) + '''.stripIndent()) }, 'Download fake audio': { - sh(script: """#!/bin/bash -xe + sh(script: '''#!/bin/bash -xe FAKE_AUDIO=/opt/openvidu-cache/fakeaudio.wav if [ ! -f ${FAKE_AUDIO} ]; then sudo curl --location https://github.com/OpenVidu/openvidu/raw/master/openvidu-test-e2e/docker/fakeaudio.wav --create-dirs --output /opt/openvidu-cache/fakeaudio.wav @@ -99,7 +76,7 @@ def prepareTestingEnvironment() { echo "File ${FAKE_AUDIO} already exists" fi sudo cp /opt/openvidu-cache/barcode.y4m /opt/openvidu/fakeaudio.wav - """.stripIndent()) + '''.stripIndent()) }, 'Download custom layout': { sh 'sudo curl --location https://raw.githubusercontent.com/OpenVidu/openvidu/master/openvidu-test-e2e/docker/my-custom-layout/index.html --create-dirs --output /opt/openvidu-cache/test-layouts/layout1/index.html' @@ -107,4 +84,32 @@ def prepareTestingEnvironment() { ) } +def removeStrandedContainers() { + println('Removing stranded containers') + sh(script: '''#!/bin/bash -xe + declare -a arr=("openvidu/openvidu-test-e2e:" + "openvidu/openvidu-pro-test-e2e:" + "selenium/standalone-chrome:" + "selenium/standalone-firefox:" + "selenium/standalone-opera:" + "openvidu/mediasoup-controller:" + "openvidu/openvidu-server-pro:" + "openvidu/openvidu-redis:" + "openvidu/openvidu-coturn:" + "openvidu/openvidu-proxy:" + "openvidu/replication-manager:" + "docker.elastic.co/elasticsearch/elasticsearch:" + "docker.elastic.co/kibana/kibana:" + "docker.elastic.co/beats/metricbeat-oss:" + "docker.elastic.co/beats/filebeat-oss:" + "openvidu/openvidu-pro-dind-media-node:" + "kurento/kurento-media-server:" + "openvidu/media-node-controller:") + for image in "${arr[@]}" + do + docker ps -a | awk '{ print $1,$2 }' | grep "${image}" | awk '{ print $1 }' | xargs -I {} docker rm -f {} + done + '''.stripIndent()) +} + return this