switched to python for json parsing
This commit is contained in:
20
Jenkinsfile
vendored
20
Jenkinsfile
vendored
@@ -108,13 +108,21 @@ pipeline {
|
|||||||
waitUntil {
|
waitUntil {
|
||||||
sleep(time: 10, unit: 'SECONDS')
|
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(
|
vmIp = sh(
|
||||||
script: '''
|
script: """
|
||||||
curl -s -k -u "${OPNSENSE_KEY}:${OPNSENSE_SECRET}" \
|
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
|
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
|
returnStdout: true
|
||||||
).trim()
|
).trim()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user