refactor: refs #6695 simplify Docker cleanup commands in Jenkinsfile
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2025-02-13 09:08:45 +01:00
parent c9ffaae3b3
commit 79e2a7ee25
1 changed files with 2 additions and 23 deletions

25
Jenkinsfile vendored
View File

@ -178,30 +178,9 @@ def cleanDockerE2E() {
script {
def projectBranch = "${PROJECT_NAME}-${env.BRANCH_NAME}".toLowerCase()
// STOP AND REMOVE
def containers = sh(script: """
docker ps --filter "name=^${projectBranch}" --format "{{.ID}}"
""", returnStdout: true).trim()
sh """docker ps -a --filter "name=^${projectBranch}" | awk 'NR>1 {print $1}' | xargs -r docker rm -v || true"""
sh """docker network ls --filter "name=^${projectBranch}" | awk 'NR>1 {print $1}' | xargs -r docker network rm || true"""
if (containers) {
sh(script: """
echo '${containers}' | xargs docker stop
echo '${containers}' | xargs docker rm
""")
} else {
echo "No se encontraron contenedores con el prefijo '${projectBranch}'."
}
def networks = sh(script: """
docker network ls --filter "name=^${projectBranch}" --format "{{.ID}}"
""", returnStdout: true).trim()
if (networks) {
sh(script: """
echo '${networks}' | xargs docker network rm
""")
} else {
echo "No se encontraron redes con el prefijo '${projectBranch}'."
}
}
}