def comparefiles(importedjsonfile, currentjsonfile) { echo "Comparing json file: ${importedjsonfile} with: ${currentjsonfile}" if (isUnix()) { sh """ which jq if [ \$? -ne 0 ]; then exit 1; fi # jq -S sorts json output diff -c <(jq -S . "${importedjsonfile}") <(jq -S . "${currentjsonfile}") """ } else { // Jq and diffutils can be installed on windows with chocolatey powershell """ # echo Checking utilities exist # set # echo %PATH% try { if (Get-Command jq) {} } catch { echo "jq is unavailable" exit \$false } try { if (Get-Command diff) {} } catch { echo "diff is unavailable" exit \$false } # echo Sorting json in files to compare # jq -S sorts json output jq -S . "${importedjsonfile}" > temp1.txt if (\$lastexitcode -ge 1) { exit 1 } jq -S . "${currentjsonfile}" > temp2.txt if (\$lastexitcode -ge 1) { exit 1 } # echo Diffing sorted json files diff.exe -c temp1.txt temp2.txt \$lec = \$lastexitcode Remove-Item temp1.txt Remove-Item temp2.txt if (\$lec -ge 1) { exit 1 } """ } } return this;