From b4524aff8642d6918e4c83ec62d6100ecea1a90b Mon Sep 17 00:00:00 2001 From: Oscar Reimer Date: Thu, 21 Nov 2024 13:16:18 +0100 Subject: [PATCH] Support all platforms for Jenkins (#284) --- examples/templates/Jenkins/Jenkinsfile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/templates/Jenkins/Jenkinsfile b/examples/templates/Jenkins/Jenkinsfile index 6fe337f1..0aa40460 100644 --- a/examples/templates/Jenkins/Jenkinsfile +++ b/examples/templates/Jenkins/Jenkinsfile @@ -9,7 +9,19 @@ pipeline { stage('Debricked Scan') { steps { script { - sh 'curl -LsS https://github.com/debricked/cli/releases/download/release-v2/cli_linux_x86_64.tar.gz | tar -xz debricked' + // Inspiration taken from https://github.com/trustin/os-maven-plugin/blob/master/src/main/java/kr/motd/maven/os/Detector.java + def osName = System.getProperty("os.name").toLowerCase(Locale.US).replaceAll("[^a-z0-9]+", "") + if (osName.startsWith("linux")) { osName = "linux" } + else if (osName.startsWith("mac") || osName.startsWith("osx")) { osName = "macOS" } + else if (osName.startsWith("windows")) { osName = "windows" } + + def osArch = System.getProperty("os.arch").toLowerCase(Locale.US).replaceAll("[^a-z0-9]+", "") + if (osArch.matches("(x8664|amd64|ia32e|em64t|x64)")) { osArch = "x86_64" } + else if (osArch.matches("(x8632|x86|i[3-6]86|ia32|x32)")) { osArch = "i386" } + else if (osArch.matches("(aarch_64)")) { osArch = "arm64" } + + println("OS detected: " + osName + " and architecture " + osArch) + sh 'curl -LsS https://github.com/debricked/cli/releases/download/release-v2/cli_' + osName + '_' + osArch + '.tar.gz | tar -xz debricked' sh './debricked scan' } }