Skip to content

Commit

Permalink
Merge pull request #57 from jenkinsci/config-as-code
Browse files Browse the repository at this point in the history
Following are the changes in this version
1. Support for config as code feature 
2. Support for cx Origin and cx Origin Url feature
3. Includes few bug fixes
  • Loading branch information
SubhadraSahoo authored Feb 1, 2021
2 parents 82b71fd + cd24d90 commit 54c4918
Show file tree
Hide file tree
Showing 11 changed files with 586 additions and 20 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ dependencies {
compileOnly 'com.intellij:annotations:12.0',
'org.slf4j:slf4j-api:1.6.1'

compile 'com.checkmarx:cx-client-common:2020.4.107',
compile 'com.checkmarx:cx-client-common:2021.1.145',
'com.checkmarx:cx-config-provider:1.0.14',
'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.5',
'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.10.5'

Expand All @@ -55,6 +56,7 @@ dependencies {
'org.eclipse.sisu:org.eclipse.sisu.plexus:0.0.0.M5',
'org.jmockit:jmockit:1.16'


// Fails with Gradle 2.12 and up without it. Related to https://issues.jenkins-ci.org/browse/JENKINS-17129
jenkinsTest 'org.jenkins-ci.plugins:ant:1.2@jar',
'org.jenkins-ci.plugins:mailer:1.32.1@jar',
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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 = 2020.4.8
version = 2021.1.1

repositoryVersion=

Expand Down
349 changes: 337 additions & 12 deletions src/main/java/com/checkmarx/jenkins/CxScanBuilder.java

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/main/java/com/checkmarx/jenkins/CxScanResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class CxScanResult implements Action {
private Boolean sastEnabled;
private boolean osaEnabled;

//Results
//Resultsalc
private OsaScanResult osaScanResult;
private SastScanResult sastScanResult;

Expand Down Expand Up @@ -165,6 +165,12 @@ public boolean isShowResults() {
return descriptor != null && !descriptor.isHideResults();
}

public boolean isRemoveAsyncHtml() {
@Nullable
CxScanBuilder.DescriptorImpl descriptor = (CxScanBuilder.DescriptorImpl) Jenkins.getInstance().getDescriptor(CxScanBuilder.class);
return descriptor != null && (!descriptor.isAsyncHtmlRemoval() || !this.scanRanAsynchronous );
}

public boolean isOsaEnabled() {
return osaEnabled;
}
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/com/checkmarx/jenkins/configascode/ConfigAsCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.checkmarx.jenkins.configascode;

import com.typesafe.config.Optional;

public class ConfigAsCode {
@Optional
private String project;
@Optional
private String team;
@Optional
private SastConfig sast;
@Optional
private ScaConfig sca;

public ConfigAsCode() {
}

public String getTeam() {
return team;
}

public void setTeam(String team) {
this.team = team;
}

public SastConfig getSast() {
return sast;
}

public void setSast(SastConfig sast) {
this.sast = sast;
}

public String getProject() {
return project;
}

public void setProject(String project) {
this.project = project;
}

public ScaConfig getSca() {
return sca;
}

public void setSca(ScaConfig sca) {
this.sca = sca;
}
}
100 changes: 100 additions & 0 deletions src/main/java/com/checkmarx/jenkins/configascode/SastConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.checkmarx.jenkins.configascode;

import com.typesafe.config.Optional;

public class SastConfig {
@Optional
private String preset;
@Optional
private String engineConfiguration;
@Optional
private String includeExcludePattern;
@Optional
private String excludeFolders;
@Optional
private boolean incremental;
@Optional
private boolean privateScan;
@Optional
private int low;
@Optional
private int medium;
@Optional
private int high;


public SastConfig() {
}

public String getPreset() {
return preset;
}

public void setPreset(String preset) {
this.preset = preset;
}

public String getEngineConfiguration() {
return engineConfiguration;
}

public void setEngineConfiguration(String engineConfiguration) {
this.engineConfiguration = engineConfiguration;
}

public String getIncludeExcludePattern() {
return includeExcludePattern;
}

public void setIncludeExcludePattern(String includeExcludePattern) {
this.includeExcludePattern = includeExcludePattern;
}

public String getExcludeFolders() {
return excludeFolders;
}

public void setExcludeFolders(String excludeFolders) {
this.excludeFolders = excludeFolders;
}

public boolean isIncremental() {
return incremental;
}

public void setIncremental(boolean incremental) {
this.incremental = incremental;
}

public int getLow() {
return low;
}

public void setLow(int low) {
this.low = low;
}

public int getMedium() {
return medium;
}

public void setMedium(int medium) {
this.medium = medium;
}

public int getHigh() {
return high;
}

public void setHigh(int high) {
this.high = high;
}

public boolean isPrivateScan() {
return privateScan;
}

public void setPrivateScan(boolean privateScan) {
this.privateScan = privateScan;
}
}
69 changes: 69 additions & 0 deletions src/main/java/com/checkmarx/jenkins/configascode/ScaConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.checkmarx.jenkins.configascode;

import com.typesafe.config.Optional;

public class ScaConfig {
@Optional
private String fileInclude;
@Optional
private String fileExclude;
@Optional
private String pathExclude;
@Optional
private int low;
@Optional
private int medium;
@Optional
private int high;

public ScaConfig() {
}

public String getFileInclude() {
return fileInclude;
}

public void setFileInclude(String fileInclude) {
this.fileInclude = fileInclude;
}

public String getFileExclude() {
return fileExclude;
}

public void setFileExclude(String fileExclude) {
this.fileExclude = fileExclude;
}

public String getPathExclude() {
return pathExclude;
}

public void setPathExclude(String pathExclude) {
this.pathExclude = pathExclude;
}

public int getLow() {
return low;
}

public void setLow(int low) {
this.low = low;
}

public int getMedium() {
return medium;
}

public void setMedium(int medium) {
this.medium = medium;
}

public int getHigh() {
return high;
}

public void setHigh(int high) {
this.high = high;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
</style>
<div id="async-note">
<div class="async-note"><div class="async-note-title">Note:</div>
<div class="async-note-body" id="async-note-body">Job is configured to run Checkmarx scan asynchronously. Specific build scan result cannot be displayed in this mode.<br/> Displayed results are of the previous successful scan</div></div>
<div class="async-note-body" id="async-note-body">Job is configured to run Checkmarx scan asynchronously. Specific build scan result cannot be displayed in this mode</div></div>
</div>
</j:if>
<j:if test="${result.isRemoveAsyncHtml()}">
<div>
${result.getHtmlReport()}
</div>
</j:if>
<div>
${result.getHtmlReport()}
</div>
</j:forEach>
</j:if>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
with="serverUrl,username,password,timestamp,credentialsId,isProxy" />
</f:optionalBlock>

<f:optionalBlock title="Enable config as code" inline="true" field="configAsCode" checked="${instance==null?true:instance.configAsCode}">
<div style="font-weight: bold; padding: 8px;">The following fields will be overriding by config file values if exists (project name ,team name ,sast scan settings and sca scan settings.).</div>
</f:optionalBlock>

<f:entry title="Checkmarx project name" description="Existing projects appear in a completion list when server url is provided (up to 20)">
<f:combobox field="projectName" value="${instance.projectName == null?descriptor.defaultProjectName:instance.projectName}"/>
</f:entry>
Expand Down Expand Up @@ -97,11 +101,12 @@
<f:entry title="Source character encoding (configuration)" field="sourceEncoding" description="Default Configuration uses UTF-8">
<f:select />
</f:entry>

<f:optionalBlock title="Allow global comment" inline="true" field="addGlobalCommenToBuildCommet" checked="true" />
<f:entry title="Comment" field="comment">
<f:textarea />
</f:entry>


<f:optionalBlock title="Avoid duplicate project scans in queue" inline="true" field="avoidDuplicateProjectScans" />
</f:optionalBlock>
<f:optionalBlock title="Skip scan if triggered by SCM Changes" inline="true" field="skipSCMTriggers" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@
<f:optionalBlock title="Deny new Checkmarx projects creation" inline="true" field="prohibitProjectCreation"/>

<f:optionalBlock title="Hide results" inline="true" field="hideResults"/>
<f:optionalBlock title="Remove Html results in Async mode" inline="true" field="asyncHtmlRemoval"/>

<f:entry name="jobGlobalStatusOnError" title="Job status when CxSAST scan returns an error:"
field="jobGlobalStatusOnError">
<f:enum field="jobGlobalStatusOnError">${it.displayName}</f:enum>
</f:entry>
<f:entry title="Sast Comment" field="sastcomment">
<f:textarea default=""/>
</f:entry>


<f:optionalBlock title="Globally Define vulnerability thresholds for all jobs" inline="true"
field="forcingVulnerabilityThresholdEnabled">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Allow sast comment to be added to the build comment.By default the global comment is empty
</div>

0 comments on commit 54c4918

Please sign in to comment.