pipeline { agent { label 'maven' } options { timestamps() ansiColor('xterm') } stages { stage('Run Selenium Tests In Docker') { steps { sh ''' set -eux rm -rf ./artifacts mkdir -p ./artifacts EXTRA_ARGS="" if [ "${BROWSER}" = "chrome" ]; then EXTRA_ARGS="-Dchrome.binary=/usr/bin/chromium" fi CID="$(docker create \ --add-host=host.docker.internal:host-gateway \ localhost:5005/otus/test-selenium:1.0.0 \ bash -lc "set -e; cd /workspace; mvn -Dexecution.mode=${EXECUTION_MODE} -Dbrowser=${BROWSER} -Dbrowser.version= -Dselenoid.url=${SELENOID_URL} -Dbase.url=${BASE_URL} -Dselenide.headless=${HEADLESS} -Dallure.results.directory=target/allure-results ${EXTRA_ARGS} 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/target" "./artifacts/target" || true trap - EXIT INT TERM docker rm -f "${CID}" || true exit "${TEST_RC}" ''' } } } post { always { script { try { allure commandline: 'allure', includeProperties: false, jdk: '', results: [[path: 'artifacts/target/allure-results']] } catch (Exception ex) { echo "Allure publisher unavailable: ${ex.message}" } } junit allowEmptyResults: true, testResults: 'artifacts/target/surefire-reports/*.xml' archiveArtifacts allowEmptyArchive: true, artifacts: 'artifacts/target/**' } } }