Jenkins流水线Docker构建从AWS CodeArtifact安装包遇匹配分发未找到错误
Jenkins流水线Docker构建中无法从AWS CodeArtifact安装Python包问题
在Jenkins流水线执行Docker构建过程中,尝试从AWS CodeArtifact安装已发布的Python包,参考AWS示例代码后,本地终端执行相同Docker构建可正常完成,但Jenkins中构建失败。
示例Dockerfile
FROM registry.access.redhat.com/ubi9-minimal:9.1.0-1793 ARG PYTHON_VERSION=python39 ARG CODEARTIFACT_TOKEN RUN microdnf install -y ${PYTHON_VERSION} WORKDIR /usr/app RUN python -m venv /usr/app/venv ENV PATH="/usr/app/venv/bin:$PATH" RUN pip config set global.extra-index-url "https://aws:$CODEARTIFACT_TOKEN@{xxxxx}.d.codeartifact.{REGION}.amazonaws.com/pypi/{REPO}/simple/" RUN pip install package_in_repo
Jenkins流水线获取令牌代码
authToken = sh( returnStdout: true, script: 'aws codeartifact get-authorization-token \ --domain {DOMAIN} \ --domain-owner {OWNER} \ --region {REGION} \ --query authorizationToken \ --output text \ --duration-seconds 900' ).trim() image = docker.build("{ECR/REPO}:${TAG}", "--build-arg CODEARTIFACT_TOKEN='$authToken' --network host .")
构建错误信息
#13 [builder 6/8] RUN pip install package_in_repo #13 0.914 Looking in indexes: https://pypi.org/simple, https://aws:****@{domain}.d.codeartifact.{REGION}.amazonaws.com/pypi/{REPO}/simple/ #13 1.235 ERROR: Could not find a version that satisfies the requirement package_in_repo (from versions: none) #13 1.236 ERROR: No matching distribution found for package_in_repo
从错误日志看,Jenkins能访问仓库(未出现401错误),但无法找到目标包。预期包能在Jenkins中正常安装,已完成以下排查:
- 包确实存在于仓库中(本地可构建镜像且能直接pip安装)
- Jenkins具备AWS权限(使用包含AWSCodeArtifactAdminAccess的角色)
已尝试的解决方式:
- 在Docker构建中用CLI登录CodeArtifact
- 从Jenkins传递令牌
- 指定包的特定版本号
但问题仍未解决。
内容的提问来源于stack exchange,提问作者drjjm
相关产品推荐
相关产品推荐

