我使用此脚本来显示AWS Ecr中的服务器值:
def profile = "ecr"
def region = "us-east-1"
def cmd_output = "aws ecr describe-repositories --profile $profile --region $region --output yaml".execute()
def awk_cmd_output = cmd_output | ['awk', '/repositoryName:/ {print $2}'].execute()
def repo_names = awk_cmd_output.text.tokenize().reverse()
return repo_names
当我在Linux shell中运行命令时,我得到:
root@test:~# aws ecr describe-repositories --profile ecr --region us-east-1
{
"repositories": [
{
"repositoryArn": "arn23522033165aws:ecr:us-east-1:73522033165:repository/test",
"registryId": "23522033165",
"repositoryName": "test",
"repositoryUri": "23522033165.dkr.ecr.us-east-1.amazonaws.com/test",
"createdAt": "2023-09-07T22:30:50+00:00",
"imageTagMutability": "MUTABLE",
"imageScanningConfiguration": {
"scanOnPush": false
},
"encryptionConfiguration": {
"encryptionType": "AES256"
}
},
{
"repositoryArn": "arn:aws:ecr:us-east-1:23522033165:repository/test",
"registryId": "23522033165",
"repositoryName": "test-2",
"repositoryUri": "23522033165.dkr.ecr.us-east-1.amazonaws.com/test",
"createdAt": "2023-09-09T19:54:04+00:00",
"imageTagMutability": "MUTABLE",
"imageScanningConfiguration": {
"scanOnPush": false
},
"encryptionConfiguration": {
"encryptionType": "AES256"
}
},
.....
}
以上配置为工作文件。但在使用aws configure
更改aws凭据后,列表不起作用。我在安全设置中添加了API用户作为IAM用户和一个组:
但我仍然不能从注册表中列出图像版本。你知道我如何解决这个问题吗?
编辑:我这样运行脚本:
1条答案
按热度按时间nqwrtyyt1#
您应该在Jenkinsfile中提供AWS creds。要做到这一点,你需要将aws creds添加到jenkins中,并在jenkins文件中调用它们:
在单独的阶段使用withAWS Package 器
调用aws creds作为常规creds,只需忽略作业输出中的creds