diff --git a/commandline/commandline.groovy b/commandline/commandline.groovy index df99a75..38f80fa 100644 --- a/commandline/commandline.groovy +++ b/commandline/commandline.groovy @@ -2,8 +2,7 @@ String getCommandOutput(String cmd) { if (isUnix()) { return sh(returnStdout: true, script: '#!/bin/sh -e\n' + cmd).trim() } else { - return bat(returnStdout: true, script: """ - @echo off + return powershell(returnStdout: true, script: """ ${cmd} """ ).trim() diff --git a/differences/file.groovy b/differences/file.groovy index bfb8407..aa4814a 100644 --- a/differences/file.groovy +++ b/differences/file.groovy @@ -10,12 +10,12 @@ def comparefiles(importedfile, currentfile, boolean ignorewhitespace = true) { } else { // diffutils can be installed on windows with chocolatey - bat """ - REM echo Checking utilities exist - where diff - if errorlevel 1 EXIT /b 1 + powershell """ + # echo Checking utilities exist + # where diff + # if errorlevel 1 EXIT /b 1 - diff -c ${wsparameter} "${importedfile}" "${currentfile}" + diff.exe -c ${wsparameter} "${importedfile}" "${currentfile}" """ } } diff --git a/differences/json.groovy b/differences/json.groovy index 78df0bd..0556188 100644 --- a/differences/json.groovy +++ b/differences/json.groovy @@ -10,31 +10,40 @@ def comparefiles(importedjsonfile, 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 + 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 + } - REM echo Sorting json in files to compare - REM jq -S sorts json output + # echo Sorting json in files to compare + # 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 + if (\$lastexitcode -ge 1) { exit 1 } + jq -S . "${currentjsonfile}" > temp2.txt + if (\$lastexitcode -ge 1) { exit 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 + # 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 } """ } } diff --git a/meta/folder.groovy b/meta/folder.groovy index a2fd4e1..704bfc8 100644 --- a/meta/folder.groovy +++ b/meta/folder.groovy @@ -38,7 +38,7 @@ class ProductInfo extends GISJsonSerialised { pstatus = script.sh(script: "git check-ref-format --normalize \"refs/tags/${productname}\" >/dev/null 2>/dev/null", , returnStatus: true) } else { - pstatus = script.bat(script: "@git check-ref-format --normalize \"refs/tags/${productname}\" > NUL 2> NUL", , returnStatus: true) + pstatus = script.powershell(script: "git check-ref-format --normalize \"refs/tags/${productname}\" 2>&1>\$null", , returnStatus: true) } if (pstatus > 0) { script.error("The product name: ${productname} needs to be renamed as it cannot be used in a git tag name") @@ -48,7 +48,7 @@ class ProductInfo extends GISJsonSerialised { sstatus = script.sh(script: "git check-ref-format --normalize \"refs/tags/${subcomponentname}\" >/dev/null 2>/dev/null", , returnStatus: true) } else { - sstatus = script.bat(script: "@git check-ref-format --normalize \"refs/tags/${subcomponentname}\" > NUL 2> NUL", , returnStatus: true) + sstatus = script.powershell(script: "git check-ref-format --normalize \"refs/tags/${subcomponentname}\" 2>&1>\$null", , returnStatus: true) } if (sstatus > 0) { script.error("The subcomponent name: ${subcomponentname} needs to be renamed as it cannot be used in a git tag name") @@ -59,7 +59,7 @@ class ProductInfo extends GISJsonSerialised { vstatus = script.sh(script: "git check-ref-format --normalize \"refs/tags/${variant}\" >/dev/null 2>/dev/null", , returnStatus: true) } else { - vstatus = script.bat(script: "@git check-ref-format --normalize \"refs/tags/${variant}\" > NUL 2> NUL", , returnStatus: true) + vstatus = script.powershell(script: "git check-ref-format --normalize \"refs/tags/${variant}\" 2>&1>\$null", , returnStatus: true) } if (vstatus > 0) { script.error("The subcomponent name: ${variant} needs to be renamed as it cannot be used in a git tag name") diff --git a/versioncontrol/git.groovy b/versioncontrol/git.groovy index f5b2ebd..5bcb0ba 100644 --- a/versioncontrol/git.groovy +++ b/versioncontrol/git.groovy @@ -12,7 +12,7 @@ def boolean isShallowClonedRepo(String gitrootpath) { isshallowclone = sh(returnStdout: true, script: "git rev-parse --is-shallow-repository").trim().toBoolean() } else { - isshallowclone = bat(returnStdout: true, script: "@git rev-parse --is-shallow-repository").trim().toBoolean() + isshallowclone = powershell(returnStdout: true, script: "git rev-parse --is-shallow-repository").trim().toBoolean() } echo "Repo at ${gitrootpath} is shallow cloned: ${isshallowclone}" } @@ -89,9 +89,9 @@ def String checkouttoreporoot(String gitURL) { if [ \$? -ne 0 ]; then exit 1; fi """ } else { - bat """ + powershell """ git status - if errorlevel 1 EXIT /b 1 + if (\$lastexitcode -ge 1) { exit 1 } """ } } @@ -109,9 +109,9 @@ def checkgitlfsinstall() { """ } else { - bat """ + powershell """ git lfs install - if errorlevel 1 EXIT /b 1 + if (\$lastexitcode -ge 1) { exit 1 } """ } } @@ -185,6 +185,7 @@ def showsparseitemlist(ArrayList sparseitemlist = new ArrayList( } def docheckout(String gitURL, String revision, int cloneDepth, String reporootpath, boolean shallowClone, String targetDir, sparseitemlist) { + echo "Git: Checking out: URL: ${gitURL} Revision: ${revision} to: ${targetDir}" checkout([ $class: 'GitSCM', userRemoteConfigs: [ @@ -221,7 +222,7 @@ def gitinit(String targetDir, String reporootpath) { git init "${targetDir}" """ } else { - bat """ + powershell """ git init "${targetDir}" """ } @@ -245,7 +246,7 @@ def setlfsfetchinclude(String targetDir, ArrayList sparseitemlist) { git config lfs.fetchinclude "${sparseitemliststring}" """ } else { - bat """ + powershell """ git config lfs.fetchinclude "${sparseitemliststring}" """ } @@ -263,7 +264,7 @@ def gitsparserestore(String targetDir) { git reset --hard > /dev/null """ } else { - bat """ + powershell """ git rm -rf . 2> nul git clean -fxd 2> nul git reset --hard 2> nul @@ -311,8 +312,8 @@ def checkRepoExists(String gitURL) { returnStatus: true ) } else { - result = bat( script: """ - @git ls-remote "${gitURL}" CHECK_GIT_REMOTE_URL_REACHABILITY + result = powershell( script: """ + git ls-remote "${gitURL}" CHECK_GIT_REMOTE_URL_REACHABILITY """, returnStatus: true ) diff --git a/versionnumbering/do.groovy b/versionnumbering/do.groovy index 9f45f70..208a60f 100644 --- a/versionnumbering/do.groovy +++ b/versionnumbering/do.groovy @@ -13,8 +13,8 @@ def stamp(convertdetails) { """ } else { - bat """ - "${PYTHON}" -u "${stampscript}" -f "${filetoconvert}" -p "${pattern}" -s "${replacement}" + powershell """ + & "${PYTHON}" -u "${stampscript}" -f "${filetoconvert}" -p "${pattern}" -s "${replacement}" """ } } diff --git a/versionnumbering/generate.groovy b/versionnumbering/generate.groovy index 71d7bf6..405b7be 100644 --- a/versionnumbering/generate.groovy +++ b/versionnumbering/generate.groovy @@ -28,7 +28,7 @@ def getGitRevision(String gitrootpath, int basebuildnumber) { changecount = sh(returnStdout: true, script: "git rev-list HEAD --count").trim().toInteger() } else { - changecount = bat(returnStdout: true, script: "@git rev-list HEAD --count").trim().toInteger() + changecount = powershell(returnStdout: true, script: "git rev-list HEAD --count").trim().toInteger() } echo "Change count: ${changecount}" def int mvnp1 = maxversionnumber() + 1 @@ -39,21 +39,21 @@ def getGitRevision(String gitrootpath, int basebuildnumber) { gitrevision = sh(returnStdout: true, script: "git rev-parse HEAD").trim() } else { - gitrevision = bat(returnStdout: true, script: "@git rev-parse HEAD").trim() + gitrevision = powershell(returnStdout: true, script: "git rev-parse HEAD").trim() } echo "Revision: ${gitrevision}" if (isUnix()) { remoteinfo = sh(returnStdout: true, script: "git remote show origin").trim() } else { - remoteinfo = bat(returnStdout: true, script: "@git remote show origin").trim() + remoteinfo = powershell(returnStdout: true, script: "git remote show origin").trim() } echo "Remote info: ${remoteinfo}" if (isUnix()) { remoteurl = sh(returnStdout: true, script: "git config --get remote.origin.url").trim() } else { - remoteurl = bat(returnStdout: true, script: "@git config --get remote.origin.url").trim() + remoteurl = powershell(returnStdout: true, script: "git config --get remote.origin.url").trim() } echo "Remote URL: ${remoteurl}" }