pipeline { agent { label 'maven' } options { timestamps() ansiColor('xterm') } stages { stage('Run API Tests In Docker') { steps { sh ''' set -eux rm -rf ./artifacts mkdir -p ./artifacts CID="$(docker create localhost:5005/otus/test-api:1.0.0 bash -lc "set -e; cd /workspace; mvn -f citrus-tests/pom.xml test")" cleanup_container() { docker rm -f "${CID}" >/dev/null 2>&1 || true } trap cleanup_container EXIT INT TERM tar -C /workspace/otus-autotests/homework_4 -cf - . | docker cp - "${CID}:/workspace" set +e docker start -a "${CID}" TEST_RC=$? docker cp "${CID}:/workspace/citrus-tests/target" "./artifacts/citrus-target" || true trap - EXIT INT TERM docker rm -f "${CID}" || true exit "${TEST_RC}" ''' } } } post { always { junit allowEmptyResults: true, testResults: 'artifacts/citrus-target/surefire-reports/*.xml' archiveArtifacts allowEmptyArchive: true, artifacts: 'artifacts/citrus-target/**' } } }