jenkins active choise使用

active choise插件使用

jenkins Groovy Script 脚本

def gettags="python3 /data/jenkins/tools/get_images.py $service $env".execute()
return gettags.text.readLines()

get_images.py

# import json
# import heapq
# from tqdm import tqdm
# from time import sleep, time
# import traceback

import requests,sys
from requests.auth import HTTPBasicAuth
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry


login = HTTPBasicAuth('admin', 'admin')
baseurl = "harbor.harbor.com/"
harborurl = 'https://harbor.harbor.com/api/v2.0/projects/'
# 去除requests 库的ssl忽略证书的告警
requests.packages.urllib3.disable_warnings()

# Get the corresponding tags based on the name of the mirror
def get_images_tags(servicename,env):
    
    tag_url = harborurl + env +'/repositories/' + servicename + "/artifacts"
    get_tags = requests.get(tag_url, auth=login, verify=False).json()
    for tag in get_tags:
        tag = tag["tags"][0]["name"]
        image_full_name = baseurl + env+'/' + servicename + ":" + tag
        print(image_full_name)
    
if __name__ == '__main__':
    #env = str(sys.argv[1])
    servicename = str(sys.argv[1])
    env = str(sys.argv[2])
    get_images_tags(servicename,env)
posted @ 2021-12-13 11:45  蒲公英PGY  阅读(34)  评论(0)    收藏  举报