switched to python for json parsing
This commit is contained in:
20
Jenkinsfile
vendored
20
Jenkinsfile
vendored
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user