From 13854306fe57e955147f764b32c45a43318d7a36 Mon Sep 17 00:00:00 2001 From: "Subhadra.Sahoo@checkmarx.com" Date: Tue, 9 Feb 2021 21:14:29 +0530 Subject: [PATCH 1/2] Addressed the issue for cxOrigin where in the Jenkins jobs were failing because they have job name contains alpha numeric characters #AB1419 --- src/main/java/com/checkmarx/jenkins/CxScanBuilder.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/checkmarx/jenkins/CxScanBuilder.java b/src/main/java/com/checkmarx/jenkins/CxScanBuilder.java index fb1f3815..e965f335 100644 --- a/src/main/java/com/checkmarx/jenkins/CxScanBuilder.java +++ b/src/main/java/com/checkmarx/jenkins/CxScanBuilder.java @@ -1152,6 +1152,7 @@ private String getJenkinURLForTheJob(EnvVars env) { try { String jobName = env.get("JOB_NAME"); jobName = URLDecoder.decode(jobName, "UTF-8"); + jobName = jobName.replaceAll("[^.a-zA-Z0-9\\s]", " "); String jenURL = env.get("JENKINS_URL"); jenURL = jenURL.substring((jenURL.lastIndexOf("://")) + 3); String hostName = ""; @@ -1160,13 +1161,14 @@ private String getJenkinURLForTheJob(EnvVars env) { } else { hostName = jenURL; } - passedURL = hostName + " " + jobName; + passedURL = "Jenkins " + hostName + " " + jobName; + // 50 is the maximum number of characters allowed by SAST server if(passedURL.length()>50) passedURL=passedURL.substring(0,50); else passedURL=passedURL; } catch (UnsupportedEncodingException e) { - log.error("Failed to get jwnkin URL of the JOB: " + e.getMessage()); + log.error("Failed to get Jenkins URL of the JOB: " + e.getMessage()); } return passedURL; } @@ -1178,7 +1180,7 @@ private String getCxOriginUrl(EnvVars env, CxLoggerAdapter log) { try { jobName = URLDecoder.decode(jobName, "UTF-8"); } catch (UnsupportedEncodingException e) { - log.error("Failed to get jenkin URL of the JOB: " + e.getMessage()); + log.error("Failed to get name of the Jenkins Job: " + e.getMessage()); } String originUrl = jenURL+"job/"+jobName; From 7f12edd639e70f7a94c0cc5e75dfa346299bdd15 Mon Sep 17 00:00:00 2001 From: "Subhadra.Sahoo@checkmarx.com" Date: Tue, 9 Feb 2021 21:14:29 +0530 Subject: [PATCH 2/2] Addressed the issue for cxOriginUrl where in rhe Url was getting truncated after . ,+ and space #AB1419 --- gradle.properties | 2 +- .../java/com/checkmarx/jenkins/CxScanBuilder.java | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6af431eb..409b10ed 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ description = Provides automatic scan of code by Checkmarx server and shows results summary and trend in Jenkins interface. group = com.checkmarx.jenkins -version = 2021.1.1 +version = 2021.1.2 repositoryVersion= diff --git a/src/main/java/com/checkmarx/jenkins/CxScanBuilder.java b/src/main/java/com/checkmarx/jenkins/CxScanBuilder.java index fb1f3815..bc98ab4a 100644 --- a/src/main/java/com/checkmarx/jenkins/CxScanBuilder.java +++ b/src/main/java/com/checkmarx/jenkins/CxScanBuilder.java @@ -1152,6 +1152,7 @@ private String getJenkinURLForTheJob(EnvVars env) { try { String jobName = env.get("JOB_NAME"); jobName = URLDecoder.decode(jobName, "UTF-8"); + jobName = jobName.replaceAll("[^.a-zA-Z0-9\\s]", " "); String jenURL = env.get("JENKINS_URL"); jenURL = jenURL.substring((jenURL.lastIndexOf("://")) + 3); String hostName = ""; @@ -1160,13 +1161,14 @@ private String getJenkinURLForTheJob(EnvVars env) { } else { hostName = jenURL; } - passedURL = hostName + " " + jobName; + passedURL = "Jenkins " + hostName + " " + jobName; + // 50 is the maximum number of characters allowed by SAST server if(passedURL.length()>50) passedURL=passedURL.substring(0,50); else passedURL=passedURL; } catch (UnsupportedEncodingException e) { - log.error("Failed to get jwnkin URL of the JOB: " + e.getMessage()); + log.error("Failed to get Jenkins URL of the JOB: " + e.getMessage()); } return passedURL; } @@ -1175,12 +1177,6 @@ private String getJenkinURLForTheJob(EnvVars env) { private String getCxOriginUrl(EnvVars env, CxLoggerAdapter log) { String jenURL = env.get("JENKINS_URL"); String jobName = env.get("JOB_NAME"); - try { - jobName = URLDecoder.decode(jobName, "UTF-8"); - } catch (UnsupportedEncodingException e) { - log.error("Failed to get jenkin URL of the JOB: " + e.getMessage()); - } - String originUrl = jenURL+"job/"+jobName; return originUrl; }