From a236b39bef56cb69550c6d6517fb1acd9cd9789c Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Thu, 22 Oct 2015 12:21:00 +0200 Subject: [PATCH] MT#15071 Jenkins<->docker integration support The jenkins_docker_run script is invoked from Jenkins when running the docker image. The testrunner script now takes two additional arguments to support sharing test results via another docker volume and to control output format ("pretty" as default but junit for usage on Jenkins). While at it fix some quoting issue identified by shellcheck. Change-Id: Ided716e0e0ca23751b0ee2961f3e301acb80128d --- t/selenium/Dockerfile | 2 ++ t/selenium/jenkins_docker_run | 4 ++++ t/selenium/testrunner | 22 ++++++++++++++++------ 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100755 t/selenium/jenkins_docker_run diff --git a/t/selenium/Dockerfile b/t/selenium/Dockerfile index 85a3659a43..2fef0b0edb 100644 --- a/t/selenium/Dockerfile +++ b/t/selenium/Dockerfile @@ -58,6 +58,8 @@ RUN echo "cd /code && ./t/selenium/testrunner 1.2.3.4" >/home/selenium/.bash_his RUN echo "su - selenium" >/root/.bash_history EXPOSE 5999 +COPY jenkins_docker_run /home/selenium/ + WORKDIR /home/selenium ################################################################################ diff --git a/t/selenium/jenkins_docker_run b/t/selenium/jenkins_docker_run new file mode 100755 index 0000000000..47e84b07c8 --- /dev/null +++ b/t/selenium/jenkins_docker_run @@ -0,0 +1,4 @@ +#!/bin/bash +# This script is used for running the tests with proper arguments +# from within Jenkins +su - selenium -c "cd /code && ./t/selenium/testrunner $* /results/ junit" diff --git a/t/selenium/testrunner b/t/selenium/testrunner index 8769b07512..77fc4d1202 100755 --- a/t/selenium/testrunner +++ b/t/selenium/testrunner @@ -11,18 +11,22 @@ set -u PASSWORD="selenium" if [ -z "${1:-}" ] ; then - echo "Usage: $0 " >&2 + echo "Usage: $0 [] [junit]" >&2 echo - echo "Usage example: $0 192.168.88.162" + echo "Usage examples: + + $0 192.168.88.162 + $0 192.168.88.162 /results/ junit" exit 1 fi SERVER="${1}" +OUTPUT_DIRECTORY="${2:-/code/}" # vnc echo "Setting VNC password" printf '%s\n%s\n\n' "${PASSWORD}" "${PASSWORD}" | vncpasswd >/dev/null -PASSWORD_ENCODED=$(hexdump -v -e '"\\""x" 1/1 "%02X"' <$HOME/.vnc/passwd) +PASSWORD_ENCODED=$(hexdump -v -e '"\\""x" 1/1 "%02X"' < "${HOME}/.vnc/passwd") xvnc_process=$(pgrep -f 'Xvnc4 :99' || true) if [ -n "${xvnc_process:-}" ] ; then echo "Warning: existing VNC server found, not restarting Xvnc4 process (PID: $xvnc_process)." @@ -43,10 +47,16 @@ echo "Watch at test runs by connecting via VNC (password: '${PASSWORD}'):" echo "echo -e '$PASSWORD_ENCODED' >/tmp/vncpasswd ; vncviewer geometry=1280x1024x16 passwd=/tmp/vncpasswd localhost:5999" RC=0 -CATALYST_SERVER="https://${SERVER}:1443" prove -v --color -l -It/lib t/selenium/*.t | tee -a /code/selenium.pretty || RC=$? -#CATALYST_SERVER=https://${SERVER}:1443/ prove --formatter TAP::Formatter::JUnit -l -It/lib t/selenium/*.t | tee -a /code/selenium.xml || RC=$? +if [ -n "${3:-}" ] && [ "${3:-}" = "junit" ] ; then + CATALYST_SERVER=https://${SERVER}:1443/ prove --formatter TAP::Formatter::JUnit -l -It/lib t/selenium/*.t | \ + tee -a "${OUTPUT_DIRECTORY}/selenium.xml" || RC=$? +else + CATALYST_SERVER="https://${SERVER}:1443" prove -v --color -l -It/lib t/selenium/*.t | \ + tee -a "${OUTPUT_DIRECTORY}/selenium.pretty" || RC=$? +fi + echo "Finished test execution, test execution returned with exit code ${RC}." -for file in /code/selenium.pretty /code/selenium.xml ; do +for file in "${OUTPUT_DIRECTORY}/selenium.pretty" "${OUTPUT_DIRECTORY}/selenium.xml" ; do if [ -f "$file" ] ; then echo "Test results available at ${file}" fi