From 1c0f4f757ff934ac5b040e5572b8105ce690b830 Mon Sep 17 00:00:00 2001 From: jerick Date: Tue, 3 Feb 2026 08:32:03 -0500 Subject: [PATCH] switched to python for json parsing --- Jenkinsfile | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index af1cf4e..77f1ae3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -108,13 +108,21 @@ pipeline { waitUntil { 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( - script: ''' - curl -s -k -u "${OPNSENSE_KEY}:${OPNSENSE_SECRET}" \ - "https://''' + OPNSENSE_HOST + '''/api/dhcpv4/leases/searchLease" | \ - jq -r '.rows[] | select(.hostname == "''' + templateHost + '''" or .["client-hostname"] == "''' + templateHost + '''") | .address' | head -1 - ''', + script: """ + curl -s -k -u "\${OPNSENSE_KEY}:\${OPNSENSE_SECRET}" \ + "https://${OPNSENSE_HOST}/api/dhcpv4/leases/searchLease" | \ + 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 ).trim()