switched to python for json parsing

This commit is contained in:
2026-02-03 08:32:03 -05:00
parent 89717898d4
commit 1c0f4f757f

20
Jenkinsfile vendored
View File

@@ -108,13 +108,21 @@ pipeline {
waitUntil { waitUntil {
sleep(time: 10, unit: 'SECONDS') sleep(time: 10, unit: 'SECONDS')
// Query OPNSense DHCP leases API and parse with jq // Query OPNSense DHCP leases API and parse with Python
vmIp = sh( vmIp = sh(
script: ''' script: """
curl -s -k -u "${OPNSENSE_KEY}:${OPNSENSE_SECRET}" \ curl -s -k -u "\${OPNSENSE_KEY}:\${OPNSENSE_SECRET}" \
"https://''' + OPNSENSE_HOST + '''/api/dhcpv4/leases/searchLease" | \ "https://${OPNSENSE_HOST}/api/dhcpv4/leases/searchLease" | \
jq -r '.rows[] | select(.hostname == "''' + templateHost + '''" or .["client-hostname"] == "''' + templateHost + '''") | .address' | head -1 python3 -c "
''', import sys, json
data = json.load(sys.stdin)
hostname = '${templateHost}'
for row in data.get('rows', []):
if row.get('hostname') == hostname or row.get('client-hostname') == hostname:
print(row.get('address', ''))
break
"
""",
returnStdout: true returnStdout: true
).trim() ).trim()