容器中的 Azure Pipelines 代理 运行 在并发构建时抛出错误

Azure Pipelines agent running in container throwing error on concurrent builds

我在 Ubuntu 18.04 映像上构建了三个 Azure Pipeline 代理,并部署到 Kubernetes 集群。代理是 运行 最新版本 2.182.1,但使用 2.181.0 时也出现此问题。

单独执行构建管道工作得很好。构建每次都成功完成。但是每当第二个管道启动而另一个管道已经 运行 时,它每次都会在“结帐”作业上失败并出现以下错误:

The working folder U:\azp\agent\_work\s is already in use by the workspace ws_1_34;Project Collection Build Service (myaccount) on computer linux-agent-deployment-78bfb76d.

这些是三个独立且不同的代理 运行 作为单独的容器。为什么来自一个容器的作业会影响另一个容器上的作业 运行?并发构建在我的非容器 Windows 服务器上整天工作。

容器代理被部署为标准的 Kubernetes“部署”对象:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: linux-agent
  name: linux-agent-deployment
  namespace: pipelines
  annotations:
    kubernetes.io/change-cause: "update agent image to 20210304 - change from OpenJDK to Oracle Java JDK 11"
spec:
  replicas: 3
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: linux-agent
  strategy:
    rollingUpdate:
      maxUnavailable: 1
  template:
    metadata:
      labels:
        app: linux-agent
    spec:
      serviceAccountName: sa-aws-azp-pipelineagent
      containers:
        - name: linux-agent
          image: 999999999999.dkr.ecr.us-east-2.amazonaws.com/mgmt/my-linux-agent:20210304
          imagePullPolicy: IfNotPresent
          env:
            - name: AZP_URL
              value: https://dev.azure.com/myaccount
            - name: AZP_POOL
              value: EKS-Linux
            - name: AZP_TOKEN
              valueFrom:
                secretKeyRef:
                  name: azure-devops
                  key: agent-token

我的构建代理容器非常简单...

FROM ubuntu:18.04

ENV ACCEPT_EULA=y
ENV DEBIAN_FRONTEND=noninteractive
RUN echo "APT::Get::Assume-Yes \"true\";" > /etc/apt/apt.conf.d/90assumeyes
RUN ln -fs /usr/share/zoneinfo/America/Chicago /etc/localtime

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        apt-transport-https \
        ca-certificates \
        curl \
        jq \
        git \
        iputils-ping \
        libcurl4 \
        libicu60 \
        libunwind8 \
        netcat \
        dnsutils \
        wget \
        zip \
        unzip \
        telnet \
        ftp \
        file \
        time \
        tzdata \
        build-essential \
        libc6 \
        libgcc1 \
        libgssapi-krb5-2 \
        liblttng-ust0 \
        libssl1.0 \
        libstdc++6 \
        zlib1g \
        apt-utils \
        bison \
        brotli \
        bzip2 \
        dbus \
        dpkg \
        fakeroot \
        flex \
        gnupg2 \
        iproute2 \
        lib32z1 \
        libc++-dev \
        libc++abi-dev \
        libgbm-dev \
        libgconf-2-4 \
        libgtk-3-0 \
        libsecret-1-dev \
        libsqlite3-dev \
        libxkbfile-dev \
        libxss1 \
        locales \
        m4 \
        openssh-client \
        parallel \
        patchelf \
        pkg-config \
        rpm \
        rsync \
        shellcheck \
        sqlite3 \
        ssh \
        sudo \
        texinfo \
        tk \
        upx \
        xorriso \
        xvfb \
        xz-utils \
        zstd \
        zsync \
        software-properties-common

### REQUIRED APPLICATIONS

# Amazon Web Services - CLI
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
    && unzip awscliv2.zip \
    && sudo ./aws/install

# MS SQL Tools  (ONE-TIME SETUP OF MICROSOFT REPOSITORY INCLUDED)
RUN curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - \
    && curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list \
    && sudo apt-get update && sudo ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev

# Powershell Global Tool (https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7.1)
RUN sudo apt-get install -y powershell

# .NET Core SDKs (https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu)
#       see also (https://packages.microsoft.com/ubuntu/18.04/prod/dists/bionic/main/binary-amd64/) "Packages"
#       SDKs Included: 2.1, 2.2, 3.0, 3.1, 5.0
RUN sudo apt-get install -y dotnet-host \
    aspnetcore-store-2.0.0 \
    aspnetcore-store-2.0.3 \
    aspnetcore-store-2.0.5 \
    aspnetcore-store-2.0.6 \
    aspnetcore-store-2.0.7 \
    aspnetcore-store-2.0.8 \
    aspnetcore-store-2.0.9 \
    dotnet-hostfxr-2.0.7 \
    dotnet-hostfxr-2.0.9 \
    dotnet-hostfxr-2.1 \
    dotnet-hostfxr-2.2 \
    dotnet-hostfxr-3.0 \
    dotnet-hostfxr-3.1 \
    dotnet-hostfxr-5.0 \
    dotnet-runtime-deps-2.1 \
    dotnet-runtime-deps-2.2 \
    dotnet-runtime-deps-3.0 \
    dotnet-runtime-deps-3.1 \
    dotnet-runtime-deps-5.0 \
    dotnet-targeting-pack-3.0 \
    dotnet-targeting-pack-3.1 \
    dotnet-targeting-pack-5.0 \
    netstandard-targeting-pack-2.1 \
    aspnetcore-targeting-pack-3.0 \
    aspnetcore-targeting-pack-3.1 \
    aspnetcore-targeting-pack-5.0 \
    dotnet-runtime-2.1 \
    dotnet-runtime-2.2 \
    dotnet-runtime-3.0 \
    dotnet-runtime-3.1 \
    dotnet-runtime-5.0 \
    aspnetcore-runtime-2.1 \
    aspnetcore-runtime-2.2 \
    aspnetcore-runtime-3.0 \
    aspnetcore-runtime-3.1 \
    aspnetcore-runtime-5.0 \
    dotnet-sdk-2.1 \
    dotnet-sdk-2.2 \
    dotnet-sdk-3.0 \
    dotnet-sdk-3.1 \
    dotnet-sdk-5.0

# Initialize dotnet
RUN dotnet help
RUN dotnet --info

# Node.js (https://github.com/nodesource/distributions/blob/master/README.md)
RUN curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - \
    && sudo apt-get install -y nodejs \
    && node --version \
    && npm --version

# Java JDK 11
COPY JDK/ /var/cache/oracle-jdk11-installer-local/
RUN add-apt-repository -y ppa:linuxuprising/java && \
    apt-get update && \
    echo oracle-java11-installer shared/accepted-oracle-license-v1-2 select true | sudo /usr/bin/debconf-set-selections && \
    apt-get install -y oracle-java11-installer-local

ENV JAVA_HOME=/usr/lib/jvm/java-11-oracle \
    JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8

# Clean package cache
RUN rm -rf /var/lib/apt/lists/* \
    && rm -rf /etc/apt/sources.list.d/*

WORKDIR /azp

COPY ./start.sh .
RUN chmod +x start.sh

CMD ["./start.sh"]

我做错了什么?

已找到解决方案。这是我为遇到此问题的任何人解决此问题的方法 post:

我发现了 Azure Pipeline 代理的 helm chart - emberstack/docker-azure-pipelines-agent - 在浏览了内容之后,发现了过去几天盯着我看的东西:"StatefulSets "

简单,易于测试,到目前为止运行良好。我将我的 k8s 清单重构为一个 StatefulSet 对象,并且代理已启动并能够 运行 并发构建。还有更多的测试要做,但在这一点上看起来非常积极。

apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: linux-agent
  name: linux-pipeline-agent
  namespace: pipelines
  annotations:
    kubernetes.io/change-cause: "Init 20210304 - Oracle Java JDK 11"
spec:
  podManagementPolicy: Parallel
  replicas: 3
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: linux-agent
  serviceName: agent-svc
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: linux-agent
    spec:
      serviceAccountName: sa-aws-azp-pipelineagent
      containers:
        - name: linux-agent
          image: 999999999999.dkr.ecr.us-east-2.amazonaws.com/mgmt/my-linux-agent:20210304
          imagePullPolicy: IfNotPresent
          env:
            - name: AZP_AGENT_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
            - name: AZP_URL
              value: https://dev.azure.com/myaccount
            - name: AZP_POOL
              value: EKS-Linux
            - name: AZP_TOKEN
              valueFrom:
                secretKeyRef:
                  name: azure-devops
                  key: agent-token