Jenkinsfile: improved removeStrandedContainers

pull/664/head
pabloFuente 2021-11-02 14:26:46 +01:00
parent ada73560d6
commit ef88b86e01
2 changed files with 33 additions and 26 deletions

View File

@ -165,6 +165,7 @@ node('container') {
currentBuild.result = 'FAILURE' currentBuild.result = 'FAILURE'
} finally { } finally {
environmentStop() environmentStop()
commonFunctions.removeStrandedContainers(false)
} }
} }
} }

View File

@ -21,7 +21,7 @@ def prepareTestingEnvironment() {
sh 'sudo rm -rf /opt/openvidu-cache/.m2/repository/org/kurento || true' sh 'sudo rm -rf /opt/openvidu-cache/.m2/repository/org/kurento || true'
}, },
'Removing stranded containers': { 'Removing stranded containers': {
removeStrandedContainers() removeStrandedContainers(true)
} }
) )
@ -84,32 +84,38 @@ def prepareTestingEnvironment() {
) )
} }
def removeStrandedContainers() { def removeStrandedContainers(removeTestingContainers) {
println('Removing stranded containers') println('Removing stranded containers')
sh(script: '''#!/bin/bash -xe script {
declare -a arr=("openvidu/openvidu-test-e2e:" env.removeTestingContainers = removeTestingContainers
"openvidu/openvidu-pro-test-e2e:" sh(script: '''#!/bin/bash -xe
"selenium/standalone-chrome:" declare -a arr=("selenium/standalone-chrome:"
"selenium/standalone-firefox:" "selenium/standalone-firefox:"
"selenium/standalone-opera:" "selenium/standalone-opera:"
"openvidu/mediasoup-controller:" "openvidu/mediasoup-controller:"
"openvidu/openvidu-server-pro:" "openvidu/openvidu-server-pro:"
"openvidu/openvidu-redis:" "openvidu/openvidu-redis:"
"openvidu/openvidu-coturn:" "openvidu/openvidu-coturn:"
"openvidu/openvidu-proxy:" "openvidu/openvidu-proxy:"
"openvidu/replication-manager:" "openvidu/replication-manager:"
"docker.elastic.co/elasticsearch/elasticsearch:" "docker.elastic.co/elasticsearch/elasticsearch:"
"docker.elastic.co/kibana/kibana:" "docker.elastic.co/kibana/kibana:"
"docker.elastic.co/beats/metricbeat-oss:" "docker.elastic.co/beats/metricbeat-oss:"
"docker.elastic.co/beats/filebeat-oss:" "docker.elastic.co/beats/filebeat-oss:"
"openvidu/openvidu-pro-dind-media-node:" "openvidu/openvidu-pro-dind-media-node:"
"kurento/kurento-media-server:" "kurento/kurento-media-server:"
"openvidu/media-node-controller:") "openvidu/media-node-controller:")
for image in "${arr[@]}" if [ "${removeTestingContainers}" == "true" ]; then
do arr+=("openvidu/openvidu-test-e2e:")
docker ps -a | awk '{ print $1,$2 }' | grep "${image}" | awk '{ print $1 }' | xargs -I {} docker rm -f {} arr+=("openvidu/openvidu-pro-test-e2e:")
done fi
'''.stripIndent()) for image in "${arr[@]}"
do
docker ps -a | awk '{ print $1,$2 }' | grep "${image}" | awk '{ print $1 }' | xargs -I {} docker rm -f {}
done
docker ps -a
'''.stripIndent())
}
} }
return this return this