无法在Jenkins活动选项中列出图像标签

ar5n3qh5  于 12个月前  发布在  Jenkins
关注(0)|答案(1)|浏览(101)

我使用此脚本来显示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用户和一个组:

但我仍然不能从注册表中列出图像版本。你知道我如何解决这个问题吗?
编辑:我这样运行脚本:

nqwrtyyt

nqwrtyyt1#

您应该在Jenkinsfile中提供AWS creds。要做到这一点,你需要将aws creds添加到jenkins中,并在jenkins文件中调用它们:

pipeline {
  options {
     withAWS(credentials: 'AWS_CREDENTIALS_ID', region: 'YOUR_REGION')
  }

在单独的阶段使用withAWS Package 器

pipeline {
  agent any
  stages {
    stage('hello AWS') {
      steps {
        withAWS(credentials: 'aws-credentials', region: 'your_region') {
          s3Upload acl: 'Private', bucket: 'bucket_name', file: 'hello.txt'
        }

调用aws creds作为常规creds,只需忽略作业输出中的creds

pipeline {
  agent {
    label 'master'
  }
  environment {
     ANY_TEXT_HERE = credentials('AWS_CREDENTIALS_ID_HERE')
  }

相关问题