42 lines
1.2 KiB
Groovy
42 lines
1.2 KiB
Groovy
def comparefiles(importedjsonfile, currentjsonfile) {
|
|
echo "Comparing 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
|
|
bat """
|
|
REM echo Checking utilities exist
|
|
REM set
|
|
REM echo %PATH%
|
|
where jq
|
|
if errorlevel 1 EXIT /b 1
|
|
where diff
|
|
if errorlevel 1 EXIT /b 1
|
|
|
|
REM echo Sorting json in files to compare
|
|
REM jq -S sorts json output
|
|
jq -S . "${importedjsonfile}" > temp1.txt
|
|
if errorlevel 1 EXIT /b 1
|
|
jq -S . "${importedjsonfile}" > temp2.txt
|
|
if errorlevel 1 EXIT /b 1
|
|
|
|
REM echo Diffing sorted json files
|
|
diff -c temp1.txt temp2.txt
|
|
set el=%errorlevel%
|
|
|
|
del temp1.txt
|
|
del temp2.txt
|
|
|
|
REM echo Diffing result: %el%
|
|
if %el% GEQ 1 EXIT /b 1
|
|
"""
|
|
}
|
|
}
|
|
|
|
return this;
|