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)

浙公网安备 33010602011771号