jenkins 发版获取镜像仓库中tag

  • 阿里云国际版折扣https://www.yundadi.com

  • 阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

    一、安装阿里云linux客户端工具

    选择官网下载地址

    # 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进行子账号权限管理

    创建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"

    五、Jenkins配置

    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



  • 阿里云国际版折扣https://www.yundadi.com

  • 阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6