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()