一宝恶、安裝阿里云linux客戶端工具
選擇官網(wǎng)下載地址
# 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進行子賬號權(quán)限管理
創(chuàng)建RAM子賬號丽蝎,并對該子賬號授權(quán)屠阻,記錄賬號的AccessKey ID等信息
權(quán)限名稱
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:阿里云賬號中鏡像倉庫的區(qū)位(這邊是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
image.png
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
image.png
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
image.png
image.png