如何从自托管的Ubuntu Docker容器中访问junit测试-在Azure发布管道中运行

时间:2020-05-12 17:46:47

标签: bash docker azure-devops azure-devops-self-hosted-agent

我的问题: 蔚蓝管道上的python / selenium测试框架报告-无法通过任何任务访问管道上我的自托管ubuntu容器

我尝试了以下操作:

  • 我最初有一个win2016-vs2017容器-该容器具有git-enterprise拉取功能,将我的python框架作为工件与管道上的任务一起执行,但尽管安装了chrome,但我始终无法启动测试并指向我的python-framework中的chrome diver,我无法获取该代理的任何体面的日志记录或详细信息,因此转到了自己托管的docker ..

  • 我已将框架复制到自托管的ubuntu16容器中-运行我的测试并将其上传到azure-我知道我的测试已通过100%,并希望访问和发布junit报告以将其发布到azure。

  • 我尝试使用docker创建一个卷,但是在运行代理的管道上运行的bash任务中看不到该文件夹​​

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"]

我的docker命令:

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

0 个答案:

没有答案