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 }