0

My problem: python/selenium test framework reporting on an azure pipeline - unable to access my self-hosted ubuntu container on the pipeline with any task

I tried the following:

  • I originally had a win2016-vs2017 container - which had a git-enterprise pull bringing in my python-framework as an artifact to execute with tasks on the pipeline but I could never get the tests to launch despite installing chrome and pointing to a chrome diver within my python-framework, I was unable to get any decent logging or detail on that agent so moved on to docker self hosted ..

  • I have copied my framework into the self hosted ubuntu16 container - ran my tests and uploaded it to azure - I know that my tests have passed 100% and would like to access and publish the junit reports to azure...

  • I have tried creating a volume with docker but I can't see that folder from inside a bash task running on the pipeline where I have the agent running

Dockerfile:

FROM ubuntu:16.04
BEHAVE_TARGET_URL with BEHAVE_BROWSER browser
ARG BEHAVE_TARGET_URL='https:***'
ARG BEHAVE_BROWSER=chrome

RUN echo $PATH
RUN echo "APT::Get::Assume-Yes \"true\";" > /etc/apt/apt.conf.d/90assumeyes
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
        ca-certificates \
        curl \
        jq \
        git \
        iputils-ping \
        libcurl3 \
        libicu55 \
        libunwind8 \
        netcat \
        python3 \
        python3-pip \
        python3-wheel \
        python3-setuptools \
        unzip \
        wget \
        apt-transport-https \
        gnupg \
        hicolor-icon-theme \
        libcanberra-gtk* \
        libgl1-mesa-dri \
        libgl1-mesa-glx \
        libpango1.0-0 \
        libpulse0 \
        libv4l-0 \
        fonts-symbola \
        && curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
        && echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list \
        && apt-get update && apt-get install -y \
        google-chrome-stable \
        --no-install-recommends \
        && apt-get purge --auto-remove -y curl \
        && rm -rf /var/lib/apt/lists/*

WORKDIR /azp
COPY . .

RUN pip3 install --upgrade pip && pip3 install -r requirements.txt

RUN wget -N https://chromedriver.storage.googleapis.com/81.0.4044.138/chromedriver_linux64.zip -P ~/ && \
  unzip ~/chromedriver_linux64.zip -d ~/ && \
  rm ~/chromedriver_linux64.zip && \
  mv -f ~/chromedriver /usr/local/bin/chromedriver && \
  chown root:root /usr/local/bin/chromedriver && \
  chmod 0755 /usr/local/bin/chromedriver  && \
  google-chrome --version && chromedriver --version

RUN dir
RUN mkdir PNG
RUN behave --tags=@smoke --junit --junit-directory=. --stop --summary --no-skipped -D spitfire_azure_ssl=${BEHAVE_TARGET_URL} -D browser=${BEHAVE_BROWSER} -D timeout_seconds=100 -D pipeline=1
RUN chmod +x start.sh
VOLUME /azp
CMD ["./start.sh"]

My docker commands:

docker build . --tag dockeragent:1.0.30
docker run -e AZP_URL=https://*** -e AZP_TOKEN=*** -e AZP_POOL="Self hosted agent docker" -e AZP_AGENT_NAME=mydockeragent dockeragent:latest

start.sh:

#!/bin/bash
set -e

if [ -z "$AZP_URL" ]; then
  echo 1>&2 "error: missing AZP_URL environment variable"
  exit 1
fi

if [ -z "$AZP_TOKEN_FILE" ]; then
  if [ -z "$AZP_TOKEN" ]; then
    echo 1>&2 "error: missing AZP_TOKEN environment variable"
    exit 1
  fi

  AZP_TOKEN_FILE=/azp/.token
  echo -n $AZP_TOKEN > "$AZP_TOKEN_FILE"
fi

unset AZP_TOKEN

if [ -n "$AZP_WORK" ]; then
  mkdir -p "$AZP_WORK"
fi

rm -rf /azp/agent
mkdir /azp/agent
cd /azp/agent

export AGENT_ALLOW_RUNASROOT="1"

cleanup() {
  if [ -e config.sh ]; then
    print_header "Cleanup. Removing Azure Pipelines agent..."

    ./config.sh remove --unattended \
      --auth PAT \
      --token $(cat "$AZP_TOKEN_FILE")
  fi
}

print_header() {
  lightcyan='\033[1;36m'
  nocolor='\033[0m'
  echo -e "${lightcyan}$1${nocolor}"
}

# Let the agent ignore the token env variables
export VSO_AGENT_IGNORE=AZP_TOKEN,AZP_TOKEN_FILE

print_header "1. Determining matching Azure Pipelines agent..."

AZP_AGENT_RESPONSE=$(curl -LsS \
  -u user:$(cat "$AZP_TOKEN_FILE") \
  -H 'Accept:application/json;api-version=3.0-preview' \
  "$AZP_URL/_apis/distributedtask/packages/agent?platform=linux-x64")

if echo "$AZP_AGENT_RESPONSE" | jq . >/dev/null 2>&1; then
  AZP_AGENTPACKAGE_URL=$(echo "$AZP_AGENT_RESPONSE" \
    | jq -r '.value | map([.version.major,.version.minor,.version.patch,.downloadUrl]) | sort | .[length-1] | .[3]')
fi

if [ -z "$AZP_AGENTPACKAGE_URL" -o "$AZP_AGENTPACKAGE_URL" == "null" ]; then
  echo 1>&2 "error: could not determine a matching Azure Pipelines agent - check that account '$AZP_URL' is correct and the token is valid for that account"
  exit 1
fi

print_header "2. Downloading and installing Azure Pipelines agent..."

curl -LsS $AZP_AGENTPACKAGE_URL | tar -xz & wait $!

source ./env.sh

trap 'cleanup; exit 130' INT
trap 'cleanup; exit 143' TERM

print_header "3. Configuring Azure Pipelines agent..."

./config.sh --unattended \
  --agent "${AZP_AGENT_NAME:-$(hostname)}" \
  --url "$AZP_URL" \
  --auth PAT \
  --token $(cat "$AZP_TOKEN_FILE") \
  --pool "${AZP_POOL:-Default}" \
  --work "${AZP_WORK:-_work}" \
  --replace \
  --acceptTeeEula & wait $!

# remove the administrative token before accepting work
rm $AZP_TOKEN_FILE

print_header "4. Running Azure Pipelines agent..."

# `exec` the node runtime so it's aware of TERM and INT signals
# AgentService.js understands how to handle agent self-update and restart
exec ./externals/node/bin/node ./bin/AgentService.js interactive
jmaitrehenry
  • 2,190
  • 21
  • 31
mefeinOB
  • 1
  • 1
  • Could edit your question and format the code so that it's more clear to the readers. Thx – Toni Van de Voorde May 12 '20 at 19:10
  • [Toni Van de Voorde](https://stackoverflow.com/users/65456/toni-van-de-voorde) - thank you very much for that - I am new to posting - what did you do to format it? I added the ' character but it didn't seem to work for me - I must have missed something... anyway thanks - I do want people to be able to easily read it :) – mefeinOB May 13 '20 at 00:06
  • 1
    Thanks [jmaitrehenry](https://stackoverflow.com/users/772027/jmaitrehenry) for your edit suggestion! :) – mefeinOB May 13 '20 at 00:19
  • If possible, please check if this document give any help: https://mohitgoyal.co/2019/01/05/running-azure-devops-private-agents-as-docker-containers/ – Leo Liu May 13 '20 at 08:33

0 Answers0