Docker登录ECR失败,Jenkins在Powershell上发出400个错误请求

Docker登录ECR失败,Jenkins在Powershell上发出400个错误请求,docker,powershell,jenkins,kubernetes,Docker,Powershell,Jenkins,Kubernetes,我在使用Powershell对AWS ECR运行docker登录时遇到问题更具体地说,我使用下面的powershell步骤从Windows容器上的Jenkins管道(在K8S集群内)运行它 powershell“aws ecr获取登录密码--地区eu-central-1 | docker登录--用户名aws--密码stdin****.dkr.ecr.eu-central-1.amazonaws.com” 但它失败了,错误如下: 09:24:32 At C:\Jenkins\agent\work

我在使用Powershell对AWS ECR运行
docker登录时遇到问题
更具体地说,我使用下面的
powershell
步骤从Windows容器上的Jenkins管道(在K8S集群内)运行它

powershell“aws ecr获取登录密码--地区eu-central-1 | docker登录--用户名aws--密码stdin****.dkr.ecr.eu-central-1.amazonaws.com”

但它失败了,错误如下:

09:24:32  At C:\Jenkins\agent\workspace\test\awsIamRole-Test@tmp\durable-e2ffd0da\powershellWrapper.ps1:3 char:1
09:24:32  + & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
09:24:32  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
09:24:32      + CategoryInfo          : NotSpecified: (Error response ...400 Bad Request    :String) [], RemoteException
09:24:32      + FullyQualifiedErrorId : NativeCommandError
奇怪的行为是,如果我在容器上(在本地计算机和集群上)手动运行命令,一切正常,登录成功。下面是容器的Dockerfile

# escape=`
FROM mcr.microsoft.com/windows/servercore:1809

SHELL ["powershell"] 

RUN Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN choco install docker -y 
RUN choco install awscli --version=2.1.15 -y
RUN choco install jq -y
由于容器在EC2实例上运行,并且我需要在容器内运行Docker,因此在K8S上启动容器时,我绑定到底层EC2机器的Docker套接字,如下所示(它可以工作,因为管道中的
Docker ps
显示正确的结果)


有什么问题吗?

我设法解决了

问题原因 这个问题似乎与在Jenkins上运行powershell时如何管理管道有关,并且出于某种原因(我还没有弄清楚),在令牌之前添加了一行新行,以便

token
命令的第二部分作为输入获取


token
它可能会像根本没有输入一样处理它,并且
--password stdin
标志使它在
BadRequest
状态下失败

变通办法 因为我无法删除这一新行,所以我使用它作为解决方法

powershell 'docker login --username AWS -p $(aws ecr get-login-password --region eu-central-1 ) ****.dkr.ecr.eu-central-1.amazonaws.com'

在使用Powershell时遇到了相同的问题,我使用了不同的CLI进行交互,因为它似乎对Powershell不起作用。您是否可以尝试以管理员身份运行该命令?在PowerShell中使用git bash terminal运行该命令时,似乎出现了问题works@PeetvdWesthuizen你直接在PowerShell上运行时碰到这个?对我来说,直接运行它效果很好,从Jenkins运行它只是一个问题。@Yidir谢谢,但不幸的是我不能使用它。
powershell 'docker login --username AWS -p $(aws ecr get-login-password --region eu-central-1 ) ****.dkr.ecr.eu-central-1.amazonaws.com'