fix(jenkins): replace curl with python3 urllib to avoid shell glob and timeout issues
This commit is contained in:
@@ -96,21 +96,34 @@ pipeline {
|
|||||||
passwordVariable: 'HARBOR_PASS'
|
passwordVariable: 'HARBOR_PASS'
|
||||||
)
|
)
|
||||||
]) {
|
]) {
|
||||||
def harborListUrl = "${HARBOR_API}/projects/${params.HARBOR_PROJECT}/repositories?page_size=100"
|
|
||||||
def services = sh(
|
def services = sh(
|
||||||
script: """
|
script: """
|
||||||
HARBOR_LIST_URL="${harborListUrl}"
|
python3 - <<'PYEOF'
|
||||||
curl -s -u "\${HARBOR_USER}:\${HARBOR_PASS}" \\
|
import urllib.request, urllib.parse, json, sys, base64
|
||||||
--connect-timeout 10 --max-time 30 \\
|
|
||||||
"\${HARBOR_LIST_URL}" \\
|
registry = "${HARBOR_API}"
|
||||||
| python3 -c '
|
project = "${params.HARBOR_PROJECT}"
|
||||||
import sys, json
|
user = "${env.HARBOR_USER}"
|
||||||
repos = json.load(sys.stdin)
|
passwd = "${env.HARBOR_PASS}"
|
||||||
if not isinstance(repos, list):
|
|
||||||
|
params = urllib.parse.urlencode({"page_size": 100})
|
||||||
|
url = f"{registry}/projects/{project}/repositories?{params}"
|
||||||
|
|
||||||
|
req = urllib.request.Request(url)
|
||||||
|
creds = base64.b64encode(f"{user}:{passwd}".encode()).decode()
|
||||||
|
req.add_header("Authorization", f"Basic {creds}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||||
|
repos = json.loads(resp.read())
|
||||||
|
if not isinstance(repos, list):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
names = [r["name"].split("/")[-1] for r in repos]
|
names = [r["name"].split("/")[-1] for r in repos]
|
||||||
print(",".join(sorted(names)))
|
print(",".join(sorted(names)))
|
||||||
' 2>/dev/null || echo ""
|
except Exception as e:
|
||||||
|
print(f"ERROR: {e}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
PYEOF
|
||||||
""",
|
""",
|
||||||
returnStdout: true
|
returnStdout: true
|
||||||
).trim()
|
).trim()
|
||||||
@@ -146,11 +159,29 @@ print(",".join(sorted(names)))
|
|||||||
|
|
||||||
def digestResult = sh(
|
def digestResult = sh(
|
||||||
script: """
|
script: """
|
||||||
curl -s -u "\${HARBOR_USER}:\${HARBOR_PASS}" \\
|
python3 - <<'PYEOF'
|
||||||
--connect-timeout 10 \\
|
import urllib.request, json, sys, base64
|
||||||
--max-time 30 \\
|
|
||||||
"${HARBOR_API}/projects/${params.HARBOR_PROJECT}/repositories/${svc}/artifacts/${params.IMAGE_TAG}" \\
|
registry = "${HARBOR_API}"
|
||||||
| python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('digest',''))" 2>/dev/null || echo ""
|
project = "${params.HARBOR_PROJECT}"
|
||||||
|
svc = "${svc}"
|
||||||
|
tag = "${params.IMAGE_TAG}"
|
||||||
|
user = "${env.HARBOR_USER}"
|
||||||
|
passwd = "${env.HARBOR_PASS}"
|
||||||
|
|
||||||
|
url = f"{registry}/projects/{project}/repositories/{svc}/artifacts/{tag}"
|
||||||
|
req = urllib.request.Request(url)
|
||||||
|
creds = base64.b64encode(f"{user}:{passwd}".encode()).decode()
|
||||||
|
req.add_header("Authorization", f"Basic {creds}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||||
|
data = json.loads(resp.read())
|
||||||
|
print(data.get("digest", ""))
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR: {e}", file=sys.stderr)
|
||||||
|
sys.exit(0)
|
||||||
|
PYEOF
|
||||||
""",
|
""",
|
||||||
returnStdout: true
|
returnStdout: true
|
||||||
).trim()
|
).trim()
|
||||||
|
|||||||
Reference in New Issue
Block a user