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



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

单独执行构建管道工作得很好。每次构建都成功完成。但是,每当在另一个管道已经运行时启动第二个管道时,它每次都会在"checkout"时失败。有以下错误的作业:

The working folder U:azpagent_work1s 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://learn.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://learn.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"]

我做错了什么?

已找到解决方案。以下是我为看到这篇文章的人解决这个问题的方法:

我发现了一个Azure Pipeline代理的helm图- emberstack/docker-azure-pipelines-agent -在内容中戳了一下之后,发现了过去几天盯着我的东西:" statfulsets">

简单,易于测试,到目前为止运行良好。我将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

最新更新