jenkins 发版获取镜像仓库中tag
阅读原文时间:2023年08月26日阅读:1

选择官网下载地址

# wget wget https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz

# tar -xf aliyun-cli-linux-latest-amd64.tgz

# cp aliyun /usr/local/bin

创建RAM子账号,并对该子账号授权,记录账号的AccessKey ID等信息

权限名称

AliyunContainerRegistryFullAccess

AliyunContainerRegistryReadOnlyAccess

# aliyun configure
Configuring profile 'default' in 'AK' authenticate mode...
Access Key Id [*********************kCg]:
Access Key Secret [***************************2w7]:
Default Region Id [cn-hangzhou]:
Default Output Format [json]: json (Only support json)
Default Language [zh|en] zh:
Saving profile[default] ...Done.
  • Access ID:RAM子账号的ID

  • Access Secret:RAM子账号的Secret

  • Region ID:阿里云账号中镜像仓库的区位(这边是cn-hangzhou)

  • Language:zh

    aliyun cr GetRepoTags --help
    阿里云CLI命令行工具 3.0.64

    Product: cr (容器镜像服务)
    Method: GET
    PathPattern: /repos/[RepoNamespace]/[RepoName]/tags

    Parameters:
    --RepoName String Required
    --RepoNamespace String Required
    --Page Integer Optional
    --PageSize Integer Optional

  • 使用--help 查看使用方法,cr为容器镜像服务

    aliyun cr GetRepoTags --RepoNamespace xxxx --RepoName xxxxxxx

    {
    "data": {
    "page": 1,
    "pageSize": 30,
    "tags": [
    {
    "digest": "c06e0fe7ca4759dc15c517007a21465cfce16cc35ac3f83058c306880f804ea9",
    "imageCreate": 1606813621000,
    "imageId": "878046fe77276fe5ff5883537a5435734c9d21a953b271534df8d01f4da14e1e",
    "imageSize": 154166831,
    "imageUpdate": 1606813621000,
    "status": "NORMAL",
    "tag": "1.0.2"
    }
    ],
    "total": 1
    }
    }

  • --RepoNamespace:阿里云容器镜像服务中的命名空间

  • --RepoName:阿里云容器镜像服务中的镜像仓库名称

只获取tag,需要提前安装jq命令

# aliyun cr GetRepoTags --RepoNamespace xxxx --RepoName xxxxxxxxx | jq ".data.tags[].tag"
"1.0.2"


import groovy.json.JsonSlurperClassic

def cmd = "/var/jenkins_home/aliyun cr GetRepoListByNamespace   --RepoNamespace  payfun --PageSize  100"
def aliyun_images_json = cmd.execute()

// Parse JSON into Groovy object
def data = new JsonSlurperClassic().parseText(aliyun_images_json.text)

// Prepare the results list
def aliyun_images = [];

// Add all tags
data.data.repos.each { aliyun_images.push(it.repoName) }

return aliyun_images

import groovy.json.JsonSlurperClassic

def cmd1 = "/var/jenkins_home/aliyun cr  GetRepoTags  --RepoNamespace  payfun --RepoName  " +  project
def aliyun_tags_json = cmd1.execute()

// Parse JSON into Groovy object
def data1 = new JsonSlurperClassic().parseText(aliyun_tags_json.text)

// Prepare the results list
def aliyun_tags = [];

// Add all tags
data1.data.tags.each { aliyun_tags.push(it.tag) }

return aliyun_tags

import groovy.json.JsonSlurperClassic

def cmd1 = "/var/jenkins_home/aliyun cr  GetRepoTags  --RepoNamespace  xxxx --RepoName  " +  'aiotjp-data'
def aliyun_tags_json = cmd1.execute()

// Parse JSON into Groovy object
def data1 = new JsonSlurperClassic().parseText(aliyun_tags_json.text)

// Prepare the results list
def aliyun_tags = [];

// Add all tags
data1.data.tags.each { aliyun_tags.push(it.tag) }

return aliyun_tags

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章