Skip to content

Commit daeba2f

Browse files
Merge pull request #89 from jenkinsci/groupid-teampath-support
Groupid teampath support
2 parents d593a2a + 1ca3ece commit daeba2f

9 files changed

Lines changed: 154 additions & 41 deletions

File tree

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ dependencies {
6060
'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.11.3',
6161
'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.5',
6262
'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.10.5',
63-
'org.apache.logging.log4j:log4j-slf4j-impl:2.16.0',
64-
'org.apache.logging.log4j:log4j-api:2.16.0',
65-
'org.apache.logging.log4j:log4j-core:2.16.0'
63+
'org.apache.logging.log4j:log4j-slf4j-impl:2.17.0',
64+
'org.apache.logging.log4j:log4j-api:2.17.0',
65+
'org.apache.logging.log4j:log4j-core:2.17.0'
6666
constraints {
6767
implementation('io.vertx:vertx-web:3.9.7') {
6868
because 'previous versions have a bug impacting this application'

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
description = Provides automatic scan of code by Checkmarx server and shows results summary and trend in Jenkins interface.
22
group = com.checkmarx.jenkins
3-
version = 2021.4.3
3+
version = 2022.1.1
44

55
repositoryVersion=
66

src/main/java/com/checkmarx/jenkins/CxScanBuilder.java

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@
4040
import jenkins.model.Jenkins;
4141
import jenkins.tasks.SimpleBuildStep;
4242
import net.sf.json.JSONObject;
43+
4344
import org.apache.commons.io.FileUtils;
4445
import org.apache.commons.io.IOUtils;
4546
import org.apache.commons.lang3.StringEscapeUtils;
4647
import org.apache.commons.lang3.StringUtils;
48+
import org.apache.commons.lang3.SystemUtils;
4749
import org.jetbrains.annotations.NotNull;
4850
import org.jetbrains.annotations.Nullable;
4951
import org.kohsuke.stapler.*;
@@ -1320,7 +1322,15 @@ private CxScanConfig resolveConfiguration(Run<?, ?> run, DescriptorImpl descript
13201322
} else {
13211323
ret.setProxy(false);
13221324
}
1323-
teamPath = getTeamNameFromId(cxConnectionDetails, descriptor, groupId);
1325+
1326+
/*
1327+
* Pipeline script can provide grouoId or teamPath
1328+
* teamPath will take precedence if it is not empty.
1329+
* Freestyle job always send groupId, hence initializing teamPath using groupId
1330+
*/
1331+
if (!StringUtil.isNullOrEmpty(groupId) && StringUtil.isNullOrEmpty(teamPath)) {
1332+
teamPath = getTeamNameFromId(cxConnectionDetails, descriptor, groupId);
1333+
}
13241334
//project
13251335
ret.setProjectName(env.expand(projectName.trim()));
13261336
ret.setTeamPath(teamPath);
@@ -1534,6 +1544,20 @@ private AstScaConfig getScaConfig(Run<?, ?> run, EnvVars env, DependencyScanConf
15341544
result.setTenant(dsConfig.scaTenant);
15351545
result.setTeamPath(dsConfig.scaTeamPath);
15361546
result.setIncludeSources(dsConfig.isIncludeSources);
1547+
1548+
//add SCA Resolver code here
1549+
if (dsConfig.enableScaResolver != null
1550+
&& SCAScanType.SCA_RESOLVER.toString().equalsIgnoreCase(dsConfig.enableScaResolver.toString())) {
1551+
scaResolverPathExist(dsConfig.pathToScaResolver);
1552+
validateScaResolverParams(dsConfig.scaResolverAddParameters);
1553+
result.setEnableScaResolver(true);
1554+
}
1555+
else
1556+
result.setEnableScaResolver(false);
1557+
1558+
result.setPathToScaResolver(dsConfig.pathToScaResolver);
1559+
result.setScaResolverAddParameters(dsConfig.scaResolverAddParameters);
1560+
15371561
UsernamePasswordCredentials credentials = CxConnectionDetails.getCredentialsById(dsConfig.scaCredentialsId, run);
15381562
if (credentials != null) {
15391563
result.setUsername(credentials.getUsername());
@@ -1908,6 +1932,50 @@ private boolean isSkipScan(final Run<?, ?> run) {
19081932
}
19091933
return allowedCauses.isEmpty();
19101934
}
1935+
1936+
private boolean scaResolverPathExist(String pathToResolver) {
1937+
pathToResolver = pathToResolver + File.separator + "ScaResolver";
1938+
if(!SystemUtils.IS_OS_UNIX)
1939+
pathToResolver = pathToResolver + ".exe";
1940+
1941+
File file = new File(pathToResolver);
1942+
if(!file.exists())
1943+
{
1944+
throw new CxClientException("SCA Resolver path does not exist. Path="+file.getAbsolutePath());
1945+
}
1946+
return true;
1947+
}
1948+
1949+
private void validateScaResolverParams(String additionalParams) {
1950+
1951+
String[] arguments = additionalParams.split(" ");
1952+
Map<String, String> params = new HashMap<>();
1953+
1954+
for (int i = 0; i < arguments.length ; i++) {
1955+
if(arguments[i].startsWith("-") && (i+1 != arguments.length && !arguments[i+1].startsWith("-")))
1956+
params.put(arguments[i], arguments[i+1]);
1957+
else
1958+
params.put(arguments[i], "");
1959+
}
1960+
1961+
String dirPath = params.get("-s");
1962+
if(StringUtils.isEmpty(dirPath))
1963+
throw new CxClientException("Source code path (-s <source code path>) is not provided.");
1964+
fileExists(dirPath);
1965+
1966+
String projectName = params.get("-n");
1967+
if(StringUtils.isEmpty(projectName))
1968+
throw new CxClientException("Project name parameter (-n <project name>) must be provided to ScaResolver.");
1969+
1970+
}
1971+
1972+
private void fileExists(String file) {
1973+
1974+
File resultPath = new File(file);
1975+
if (!resultPath.exists()) {
1976+
throw new CxClientException("Path does not exist. Path= " + resultPath.getAbsolutePath());
1977+
}
1978+
}
19111979

19121980
/**
19131981
* Called when this plugin is initialized during Jenkins startup. Invoked by Jenkins using reflection.

src/main/java/com/checkmarx/jenkins/DependencyScanConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public class DependencyScanConfig {
7676

7777
@DataBoundSetter
7878
public boolean isIncludeSources;
79+
80+
@DataBoundSetter
81+
public SCAScanType enableScaResolver;
82+
83+
@DataBoundSetter
84+
public String pathToScaResolver;
85+
86+
@DataBoundSetter
87+
public String scaResolverAddParameters;
7988

8089
@DataBoundSetter
8190
public String fsaVariables;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.checkmarx.jenkins;
2+
3+
public enum SCAScanType {
4+
SCA_RESOLVER,
5+
MANIFEST
6+
}

src/main/resources/com/checkmarx/jenkins/CxScanBuilder/config.jelly

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -190,42 +190,59 @@
190190
</f:entry>
191191

192192
<f:validateButton title="Test Connection" progress="Testing..." method="testScaConnection"
193-
with="scaServerUrl,scaAccessControlUrl,scaCredentialsId,scaTenant,scaTimeout"/>
194-
195-
<f:entry title="Package Manager's Config File(s) Path" field="scaConfigFile">
196-
<f:textarea value="${instance.dependencyScanConfig.scaConfigFile}" />
197-
</f:entry>
198-
199-
<f:entry title="Private Registry Environment Variable" field="scaEnvVariables">
200-
<f:textarea value="${instance.dependencyScanConfig.scaEnvVariables}" />
201-
</f:entry>
202-
203-
204-
<f:optionalBlock title="Include Sources" field="isIncludeSources"
205-
inline="true" checked="${instance.dependencyScanConfig.isIncludeSources}"/>
206-
207-
<f:optionalBlock title="Enable Exploitable Path" field="isExploitablePath"
208-
inline="true" checked="${instance.dependencyScanConfig.isExploitablePath}">
209-
210-
<f:optionalBlock title="Use global settings (${descriptor.credentialsDescription})" field="useJobLevelSastDetails"
211-
inline="true" negative="true" checked="${!instance.dependencyScanConfig.useJobLevelSastDetails}">
212-
213-
<f:entry title="CxSAST Server Url" field="scaSastServerUrl">
214-
<f:textbox default="${descriptor.dependencyScanConfig.serverUrl}" value="${instance.dependencyScanConfig.scaSastServerUrl}" />
215-
</f:entry>
216-
<f:entry title="CxSAST credentials" field="sastCredentialsId">
217-
<c:select value="${instance.dependencyScanConfig.sastCredentialsId}" />
218-
</f:entry>
219-
<f:validateButton title="Test Connection" progress="Testing..." method="testScaSASTConnection"
220-
with="scaSastServerUrl,password,username,timestamp,sastCredentialsId,isProxy" />
221-
</f:optionalBlock>
222-
<f:entry title="Project Full Path" field="scaSASTProjectFullPath">
223-
<f:textbox value="${instance.dependencyScanConfig.scaSASTProjectFullPath}"/>
224-
</f:entry>
225-
<f:entry title="Project ID" field="scaSASTProjectID">
226-
<f:textbox checkMethod="POST" value="${instance.dependencyScanConfig.scaSASTProjectID}"/>
227-
</f:entry>
228-
</f:optionalBlock>
193+
with="scaServerUrl,scaAccessControlUrl,scaCredentialsId,scaTenant"/>
194+
195+
<f:radioBlock checked="${instance.dependencyScanConfig.enableScaResolver == null || instance.dependencyScanConfig.enableScaResolver == 'SCA_RESOLVER'}" inline="true"
196+
name="enableScaResolver" title="Perform SCA scan using dependency resolution by SCA Resolver tool."
197+
value="SCA_RESOLVER">
198+
<!-- Sca Resolver Fields-->
199+
<f:entry title="Path to SCA Resolver" field="pathToScaResolver">
200+
<f:textbox value="${instance.dependencyScanConfig.pathToScaResolver}" />
201+
</f:entry>
202+
203+
<f:entry title="SCA Resolver Additional Parameters" field="scaResolverAddParameters">
204+
<f:textarea value="${instance.dependencyScanConfig.scaResolverAddParameters}" />
205+
</f:entry>
206+
</f:radioBlock>
207+
<f:radioBlock checked="${instance.dependencyScanConfig.enableScaResolver == null || instance.dependencyScanConfig.enableScaResolver == 'MANIFEST'}" inline="true"
208+
name="enableScaResolver" title="Perform SCA scan by uploading manifests file(s)/source to SCA Service."
209+
value="MANIFEST">
210+
<!-- Non-Sca Resolver Fields-->
211+
<f:entry title="Package Manager's Config File(s) Path" field="scaConfigFile">
212+
<f:textarea value="${instance.dependencyScanConfig.scaConfigFile}" />
213+
</f:entry>
214+
215+
<f:entry title="Private Registry Environment Variable" field="scaEnvVariables">
216+
<f:textarea value="${instance.dependencyScanConfig.scaEnvVariables}" />
217+
</f:entry>
218+
219+
<f:optionalBlock title="Include Sources" field="isIncludeSources"
220+
inline="true" checked="${instance.dependencyScanConfig.isIncludeSources}"/>
221+
222+
<f:optionalBlock title="Enable Exploitable Path" field="isExploitablePath"
223+
inline="true" checked="${instance.dependencyScanConfig.isExploitablePath}">
224+
225+
<f:optionalBlock title="Use global settings (${descriptor.credentialsDescription})" field="useJobLevelSastDetails"
226+
inline="true" negative="true" checked="${!instance.dependencyScanConfig.useJobLevelSastDetails}">
227+
228+
<f:entry title="CxSAST Server Url" field="scaSastServerUrl">
229+
<f:textbox default="${descriptor.dependencyScanConfig.serverUrl}" value="${instance.dependencyScanConfig.scaSastServerUrl}" />
230+
</f:entry>
231+
<f:entry title="CxSAST credentials" field="sastCredentialsId">
232+
<c:select value="${instance.dependencyScanConfig.sastCredentialsId}" />
233+
</f:entry>
234+
<f:validateButton title="Test Connection" progress="Testing..." method="testScaSASTConnection"
235+
with="scaSastServerUrl,password,username,timestamp,sastCredentialsId,isProxy" />
236+
</f:optionalBlock>
237+
238+
<f:entry title="Project Full Path" field="scaSASTProjectFullPath">
239+
<f:textbox value="${instance.dependencyScanConfig.scaSASTProjectFullPath}"/>
240+
</f:entry>
241+
<f:entry title="Project ID" field="scaSASTProjectID">
242+
<f:textbox checkMethod="POST" value="${instance.dependencyScanConfig.scaSASTProjectID}"/>
243+
</f:entry>
244+
</f:optionalBlock>
245+
</f:radioBlock>
229246
</f:nested>
230247
</f:radioBlock>
231248
</f:optionalBlock>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
When this flag is enabled, the plugin will use SCA Resolver utility to scan dependencies.
3+
</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
Folder path on the Jenkins node machine where ScaResolver is installed. For example: C:\Users\Installations\ScaResolver-win64 or /opt/ScaResolver-linux64.
3+
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div>
2+
Provide arguments to ScaResovler tool in the same format as supported by the ScaResolver tool. ScaResolver tool will be executed in offline mode.
3+
<p>"-s", "-n" and "-r" are mandatory parameters. Example: -s C:\Users\SampleProject -n ProjectName -r c:\output, where </p>
4+
<p> -s: Path to the source code</p>
5+
<p> -n: name of the project</p>
6+
<p> -r: local machine path where the evidence file must be stored</p>
7+
</div>

0 commit comments

Comments
 (0)