AzureDevops 扩展登录任务在基于 Ubuntu 的构建代理(在 aks pod 中)内失败。
在我的 ADO 构建代理 dockerfile 中,我有以下部分来安装 python、pip 和其他组件。但是当我们运行 Azure DevOps 扩展任务时,它失败了。
Docker 文件如下。
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
wget \
jq \
git \
iputils-ping \
libcurl4 \
libicu60 \
libunwind8 \
netcat \
telnet \
libssl1.0 \
python \
python3 \
python3-setuptools \
openjdk-11-jdk-headless \
vim \
python3-pip \
gnupg \
make \
&& rm -rf /var/lib/apt/lists/*
RUN curl -LsS https://aka.ms/InstallAzureCLIDeb | bash \
&& rm -rf /var/lib/apt/lists/*
#fix azdevops extension
RUN pip3 install -U pip
RUN pip3 install --target /opt/az/lib/python3.10/site-packages/ keyring~=17.1.1
#Instal Helm
ARG HELM_VERSION="v3.7.2"
ARG HELM_LOCATION="https://get.helm.sh"
ARG HELM_FILENAME="helm-${HELM_VERSION}-linux-amd64.tar.gz"
RUN set -x && \
wget ${HELM_LOCATION}/${HELM_FILENAME} && \
echo Verifying ${HELM_FILENAME}... && \
echo Extracting ${HELM_FILENAME}... && \
tar zxvf ${HELM_FILENAME} && mv /linux-amd64/helm /usr/local/bin/ && \
rm ${HELM_FILENAME} && rm -r /linux-amd64
#install kubectl
ENV KUBECTL_VERSION="v1.18.9"
RUN set -x && \
curl --retry 5 --retry-connrefused -LO "https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl" && \
chmod +x kubectl && \
mv kubectl /usr/local/bin/kubectl
#install node
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get -y install nodejs
## To install the Yarn package manager
RUN curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarnkey.gpg >/dev/null && \
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install yarn
RUN npm install
RUN apt-get install gcc g++ make build-essential
#install maven 3.8.6
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
&& echo "Downlaoding maven" \
&& curl -fsSL -o /tmp/apache-maven.tar.gz https://apache.osuosl.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz \
\
&& echo "Unziping maven" \
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
\
&& echo "Cleaning and setting links" \
&& rm -f /tmp/apache-maven.tar.gz \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
# 6- Define environmental variables required by Maven, like Maven_Home directory and where the maven repo is located
ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64
#install docker daemon inside docker
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
RUN echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
RUN apt-get update
RUN apt-get install docker-ce docker-ce-cli containerd.io -y
# Can be 'linux-x64', 'linux-arm64', 'linux-arm', 'rhel.6-x64'.
ENV TARGETARCH=linux-x64
RUN az extension add --name azure-devops
WORKDIR /azp
COPY ./vstsagent/ .
COPY ./start.sh .
COPY ./docker.sh .
RUN chmod +x start.sh docker.sh
CMD ["./docker.sh"]
ENTRYPOINT ["./start.sh"]
AzureDevops 任务如下。
- script: |
az config set extension.use_dynamic_install=yes_without_prompt
echo ${AZURE_DEVOPS_CLI_PAT} | az devops login
env:
AZURE_DEVOPS_CLI_PAT: $(System.AccessToken)
错误如下
Pip failed with status code 1 for package keyring~=17.1.1. Use --debug for more information
调试日志
cli.knack.cli: Command arguments: ['devops', 'login', '--debug']
cli.knack.cli: __init__ debug log:
Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x7f94085c51b0>, <function OutputProducer.on_global_arguments at 0x7f94080cd630>, <function CLIQuery.on_global_arguments at 0x7f940810a830>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'devops': ['azext_devops']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name Load Time Groups Commands
cli.azure.cli.core: Total (0) 0.000 0 0
cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
cli.azure.cli.core: Loading extensions:
cli.azure.cli.core: Name Load Time Groups Commands Directory
cli.azure.cli.core: azure-devops 0.028 60 191 /root/.azure/cliextensions/azure-devops
cli.azure.cli.core: Total (1) 0.028 60 191
cli.azure.cli.core: Loaded 60 groups, 191 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command : devops login
cli.azure.cli.core: Command table: devops login
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x7f9404230790>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/root/.azure/commands/2022-11-21.08-37-42.devops_login.1908.log'.
az_command_data_logger: command args: devops login --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x7f9404249480>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x7f9404273d00>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x7f9404273e20>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x7f94080cd6c0>, <function CLIQuery.handle_query_parameter at 0x7f940810a8c0>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x7f9404273d90>, <function DevCommandsLoader.post_parse_args at 0x7f9403607c70>]
az_command_data_logger: extension name: azure-devops
az_command_data_logger: extension version: 0.25.0
cli.knack.prompting: No tty available.
cli.azext_devops.dev.team.credentials: Getting PAT token in non-interactive mode.
cli.azext_devops.dev.common.pip_helper: installing keyring~=17.1.1
cli.azure.cli.core.extension.operations: Running: ['/usr/bin/../../opt/az/bin/python3', '-m', 'pip', 'install', 'keyring~=17.1.1', '--target', '/root/.azure/cliextensions/azure-devops', '-vv', '--disable-pip-version-check', '--no-cache-dir']
cli.azure.cli.core.extension.operations: Using pip 21.3.1 from /opt/az/lib/python3.10/site-packages/pip (python 3.10)
Non-user install due to --prefix or --target option
Created temporary directory: /tmp/pip-target-x6t9_gjz
Created temporary directory: /tmp/pip-ephem-wheel-cache-tkf13jxt
Created temporary directory: /tmp/pip-req-tracker-lqo8r3hx
Initialized build tracking at /tmp/pip-req-tracker-lqo8r3hx
Created build tracker: /tmp/pip-req-tracker-lqo8r3hx
Entered build tracker: /tmp/pip-req-tracker-lqo8r3hx
Created temporary directory: /tmp/pip-install-3nhp8jd3
1 location(s) to search for versions of keyring:
* https://pypi.org/simple/keyring/
Fetching project page and analyzing links: https://pypi.org/simple/keyring/
Getting page https://pypi.org/simple/keyring/
Found index url https://pypi.org/simple
Starting new HTTPS connection (1): pypi.org:443
Incremented Retry for (url='/simple/keyring/'): Retry(total=4, connect=None, read=None, redirect=None, status=None)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/keyring/
Starting new HTTPS connection (2): pypi.org:443
Incremented Retry for (url='/simple/keyring/'): Retry(total=3, connect=None, read=None, redirect=None, status=None)
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/keyring/
Starting new HTTPS connection (3): pypi.org:443
Incremented Retry for (url='/simple/keyring/'): Retry(total=2, connect=None, read=None, redirect=None, status=None)
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/keyring/
Starting new HTTPS connection (4): pypi.org:443
Incremented Retry for (url='/simple/keyring/'): Retry(total=1, connect=None, read=None, redirect=None, status=None)
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/keyring/
Starting new HTTPS connection (5): pypi.org:443
Incremented Retry for (url='/simple/keyring/'): Retry(total=0, connect=None, read=None, redirect=None, status=None)
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/keyring/
Starting new HTTPS connection (6): pypi.org:443
Could not fetch URL https://pypi.org/simple/keyring/: connection error: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/keyring/ (Caused by ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))) - skipping
Skipping link: not a file: https://pypi.org/simple/keyring/
Given no hashes to check 0 links for project 'keyring': discarding no candidates
ERROR: Could not find a version that satisfies the requirement keyring~=17.1.1 (from versions: none)
ERROR: No matching distribution found for keyring~=17.1.1
Exception information:
Traceback (most recent call last):
File "/opt/az/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 349, in resolve
self._add_to_criteria(self.state.criteria, r, parent=None)
File "/opt/az/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 174, in _add_to_criteria
raise RequirementsConflicted(criterion)
pip._vendor.resolvelib.resolvers.RequirementsConflicted: Requirements conflict: SpecifierRequirement('keyring~=17.1.1')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/az/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 92, in resolve
result = self._result = resolver.resolve(
File "/opt/az/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 482, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File "/opt/az/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 351, in resolve
raise ResolutionImpossible(e.criterion.information)
pip._vendor.resolvelib.resolvers.ResolutionImpossible: [RequirementInformation(requirement=SpecifierRequirement('keyring~=17.1.1'), parent=None)]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/az/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 164, in exc_logging_wrapper
status = run_func(*args)
File "/opt/az/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 205, in wrapper
return func(self, options, args)
File "/opt/az/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 338, in run
requirement_set = resolver.resolve(
File "/opt/az/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 101, in resolve
raise error from e
pip._internal.exceptions.DistributionNotFound: No matching distribution found for keyring~=17.1.1
Removed build tracker: '/tmp/pip-req-tracker-lqo8r3hx'
cli.azure.cli.core.extension.operations: Command '['/usr/bin/../../opt/az/bin/python3', '-m', 'pip', 'install', 'keyring~=17.1.1', '--target', '/root/.azure/cliextensions/azure-devops', '-vv', '--disable-pip-version-check', '--no-cache-dir']' returned non-zero exit status 1.
cli.azext_devops.dev.team.credentials: Unable to use secure credential store in this environment.
cli.azext_devops.dev.team.credentials: Please refer to alternate methods at https://aka.ms/azure-devops-cli-auth
cli.azext_devops.dev.team.credentials: using Environment variable
cli.azext_devops.dev.team.credentials: or use 'az login'
cli.azext_devops.dev.common.exception_handler: handling generic error
cli.azure.cli.core.util: azure.cli.core.util.handle_exception is called with an exception:
cli.azure.cli.core.util: Traceback (most recent call last):
File "/root/.azure/cliextensions/azure-devops/azext_devops/dev/common/credential_store.py", line 23, in set_password
import keyring
ModuleNotFoundError: No module named 'keyring'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/.azure/cliextensions/azure-devops/azext_devops/dev/team/credentials.py", line 31, in credential_set
set_credential(organization=organization, token=token)
File "/root/.azure/cliextensions/azure-devops/azext_devops/dev/common/_credentials.py", line 33, in set_credential
cred_store.set_password(key, token)
File "/root/.azure/cliextensions/azure-devops/azext_devops/dev/common/credential_store.py", line 25, in set_password
install_keyring()
File "/root/.azure/cliextensions/azure-devops/azext_devops/dev/common/pip_helper.py", line 16, in install_keyring
_install_package('keyring~=17.1.1')
File "/root/.azure/cliextensions/azure-devops/azext_devops/dev/common/pip_helper.py", line 25, in _install_package
raise CLIError('An error occurred. Pip failed with status code {} for package {}. '
knack.util.CLIError: An error occurred. Pip failed with status code 1 for package keyring~=17.1.1. Use --debug for more information.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/az/lib/python3.10/site-packages/knack/cli.py", line 233, in invoke
cmd_result = self.invocation.execute(args)
File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
raise ex
File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 718, in _run_job
return cmd_copy.exception_handler(ex)
File "/root/.azure/cliextensions/azure-devops/azext_devops/dev/common/exception_handler.py", line 31, in azure_devops_exception_handler
reraise(*sys.exc_info())
File "/opt/az/lib/python3.10/site-packages/six.py", line 703, in reraise
raise value
File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
result = cmd_copy(params)
File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
return self.handler(*args, **kwargs)
File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
return op(**command_args)
File "/root/.azure/cliextensions/azure-devops/azext_devops/dev/team/credentials.py", line 37, in credential_set
raise CLIError(ex)
knack.util.CLIError: An error occurred. Pip failed with status code 1 for package keyring~=17.1.1. Use --debug for more information.
cli.azure.cli.core.azclierror: An error occurred. Pip failed with status code 1 for package keyring~=17.1.1. Use --debug for more information.
az_command_data_logger: An error occurred. Pip failed with status code 1 for package keyring~=17.1.1. Use --debug for more information.
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x7f94042309d0>]
az_command_data_logger: exit code: 1
cli.__main__: Command ran in 8.952 seconds (init: 0.360, invoke: 8.593)
telemetry.main: Begin splitting cli events and extra events, total events: 1
telemetry.client: Accumulated 0 events. Flush the clients.
telemetry.main: Finish splitting cli events and extra events, cli events: 1
telemetry.save: Save telemetry record of length 3272 in cache
根据错误信息,似乎这个问题与package keyring~=17.1.1有关。您可以尝试升级pip并安装软件包来检查是否有效。
听起来你遇到了与笔记本电脑上特定版本的 Azure 相关的错误。建议安装2.45之前的版本即可解决问题。
安装2.45之前的任何版本