switched to jq for parsing json responses

This commit is contained in:
2026-02-02 23:05:44 -05:00
parent 6e95f759e6
commit 8cd78eb4df

14
Jenkinsfile vendored
View File

@@ -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
}