来自 AWS ECR 的 Jenkins 管道 Docker 代理

kag*_*kij 7 jenkins-pipeline aws-ecr

我需要在 Docker 中作为代理执行 Jenkins 管道,

Docker 镜像位于 AWS ECR 中,

如何通过 AWS ECR 进行身份验证以为代理提取映像?

Sou*_*abh 6

agent {
  docker {
    alwaysPull true
    image '<aws-account-Id>.dkr.ecr.us-west-2.amazonaws.com/<ecr-repo>:<tag>'
    registryUrl 'https://<aws-account-Id>.dkr.ecr.us-west-2.amazonaws.com'
    registryCredentialsId 'ecr:us-west-2:<Jenkins Credential ID>'
  }
}
Run Code Online (Sandbox Code Playgroud)

要使用 AWS ECR 存储库中的图像作为 jenkins 中的代理,首先需要添加 Credentials of Kind AWS Credentials。现在只需将上面的代码用于管道代码中的代理块即可。确保更换

  1. <aws-account>与 AWS 账户 ID。

  2. <ecr-repo>与 ECR 存储库名称

  3. <tag>与您想要使用的 ECR 图像标签。

  4. <Jenkins Credential ID>使用 Jenkins 凭据 Id 在您将凭据保存在 Jenkins 中时获得。

  5. us-west-2替换为您的 ecr 存储库区域

您可以使用https://<jenkins.url>/directive-generator/为您生成此代码。


Mzz*_*zzl 1

根据此页面https://aws.amazon.com/blogs/compute/authenticating-amazon-ecr-repositories-for-docker-cli-with-credential-helper/类似以下内容应该有效:

sh """#!/bin/bash
      docker login -u=${USER} -p=${PASS} https://aws_account_id.dkr.ecr.us-east-1.amazonaws.com
"""
Run Code Online (Sandbox Code Playgroud)