From 8cd78eb4df0a2dddff86ea75dfd2c7642503186d Mon Sep 17 00:00:00 2001 From: jerick Date: Mon, 2 Feb 2026 23:05:44 -0500 Subject: [PATCH] switched to jq for parsing json responses --- Jenkinsfile | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 828d556..da075b4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -108,21 +108,17 @@ pipeline { waitUntil { sleep(time: 10, unit: 'SECONDS') - // Query OPNSense DHCP leases API - def response = sh( + // Query OPNSense DHCP leases API and parse with jq + vmIp = sh( script: """ 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 """, returnStdout: true ).trim() - // Parse JSON and find the lease with matching hostname - def leases = readJSON text: response - def matchingLease = leases.rows?.find { it.hostname == templateHost || it['client-hostname'] == templateHost } - - if (matchingLease) { - vmIp = matchingLease.address + if (vmIp) { echo "Found IP address: ${vmIp} for hostname: ${templateHost}" return true }