-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding OWASP Dependency Check job #34
Open
kramos
wants to merge
2
commits into
Accenture:master
Choose a base branch
from
kramos:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ def regressionTestJob = freeStyleJob(projectFolderName + "/Reference_Application | |
def performanceTestJob = freeStyleJob(projectFolderName + "/Reference_Application_Performance_Tests") | ||
def deployJobToProdA = freeStyleJob(projectFolderName + "/Reference_Application_Deploy_ProdA") | ||
def deployJobToProdB = freeStyleJob(projectFolderName + "/Reference_Application_Deploy_ProdB") | ||
def owaspDepCheckJob = freeStyleJob(projectFolderName + "/OWASP_Dependency_Check") | ||
|
||
// Views | ||
def pipelineView = buildPipelineView(projectFolderName + "/Java_Reference_Application") | ||
|
@@ -145,7 +146,7 @@ codeAnalysisJob.with { | |
} | ||
label("java8") | ||
steps { | ||
copyArtifacts('Reference_Application_Unit_Tests') { | ||
copyArtifacts('Reference_Application_Build') { | ||
buildSelector { | ||
buildNumber('${B}') | ||
} | ||
|
@@ -540,3 +541,87 @@ deployJobToProdB.with { | |
) | ||
} | ||
} | ||
|
||
owaspDepCheckJob.with { | ||
description("This job uses the OWASP Dependency Check plugin to check for CVEs in the application dependencies.") | ||
wrappers { | ||
preBuildCleanup() | ||
injectPasswords() | ||
maskPasswords() | ||
sshAgent("adop-jenkins-master") | ||
} | ||
scm { | ||
git { | ||
remote { | ||
url(referenceAppGitUrl) | ||
credentials("adop-jenkins-master") | ||
} | ||
branch("*/master") | ||
} | ||
} | ||
environmentVariables { | ||
env('WORKSPACE_NAME', workspaceFolderName) | ||
env('PROJECT_NAME', projectFolderName) | ||
} | ||
label("java8") | ||
|
||
steps { | ||
maven { | ||
goals('clean install -DskipTests') | ||
mavenInstallation("ADOP Maven") | ||
} | ||
} | ||
|
||
configure { project -> | ||
project / 'builders' / 'org.jenkinsci.plugins.DependencyCheck.DependencyCheckBuilder'(plugin: '[email protected]') { | ||
skipOnScmChange false | ||
skipOnUpstreamChange false | ||
scanpath '' | ||
outdir '' | ||
datadir '' | ||
suppressionFile '' | ||
zipExtensions '' | ||
isAutoupdateDisabled false | ||
isVerboseLoggingEnabled false | ||
includeHtmlReports false | ||
useMavenArtifactsScanPath false | ||
} | ||
} | ||
|
||
configure { project -> | ||
project / 'publishers' / 'org.jenkinsci.plugins.DependencyCheck.DependencyCheckPublisher'(plugin: '[email protected]') { | ||
healthy '' | ||
unHealthy '' | ||
thresholdLimit 'low' | ||
pluginName '[DependencyCheck]' | ||
defaultEncoding '' | ||
canRunOnFailed 'false' | ||
usePreviousBuildAsReference 'false' | ||
useStableBuildAsReference 'false' | ||
useDeltaValues 'false' | ||
thresholds (plugin: '[email protected]') { | ||
unstableTotalAll '' | ||
unstableTotalHigh '' | ||
unstableTotalNormal '' | ||
unstableTotalLow '' | ||
unstableNewAll '' | ||
unstableNewHigh '' | ||
unstableNewNormal '' | ||
unstableNewLow '' | ||
failedTotalAll '' | ||
failedTotalHigh '0' | ||
failedTotalNormal '' | ||
failedTotalLow '' | ||
failedNewAll '' | ||
failedNewHigh '' | ||
failedNewNormal '' | ||
failedNewLow '' | ||
} | ||
shouldDetectModules false | ||
dontComputeNew true | ||
doNotResolveRelativePaths false | ||
pattern '' | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
193
src/test/groovy/com/java/cartridge/OwaspDependencyCheckJobSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
package com.java.cartridge | ||
|
||
import spock.lang.Unroll | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
|
||
/** | ||
* Tests that JavaReferenceApplication/OwaspDependencyCheck job works as expected. | ||
*/ | ||
class OwaspDependencyCheckJobSpec extends Specification { | ||
|
||
@Shared | ||
def helper = new DslHelper('jenkins/jobs/dsl/java_reference_application_jobs.groovy') | ||
|
||
@Shared | ||
def Node node = new XmlParser().parseText(helper.jm.savedConfigs["${helper.projectName}/OWASP_Dependency_Check"]) | ||
|
||
def 'OWASP_Dependency_Check job is exists'() { | ||
expect: | ||
helper.jm.savedConfigs[jobName] != null | ||
|
||
where: | ||
jobName = "${helper.projectName}/OWASP_Dependency_Check" | ||
} | ||
|
||
def 'job parameters not exists'() { | ||
expect: | ||
node.properties.size() == 1 | ||
node.properties['hudson.model.ParametersDefinitionProperty'].size() == 0 | ||
} | ||
|
||
def 'workspace_name and project_name env variables injected'() { | ||
expect: | ||
node.properties.EnvInjectJobProperty.size() == 1 | ||
|
||
with(node.properties.EnvInjectJobProperty) { | ||
info.size() == 1 | ||
|
||
with(info) { | ||
propertiesContent.size() == 1 | ||
|
||
with(propertiesContent) { | ||
text() == "WORKSPACE_NAME=${workspaceName}\nPROJECT_NAME=${projectName}" | ||
} | ||
} | ||
} | ||
|
||
where: | ||
workspaceName = helper.workspaceName | ||
projectName = helper.projectName | ||
} | ||
|
||
def 'job assigned to java8 node'() { | ||
expect: | ||
node.assignedNode.size() == 1 | ||
node.assignedNode.text() == 'java8' | ||
} | ||
|
||
def 'wrappers exists'() { | ||
expect: | ||
node.buildWrappers.size() == 1 | ||
} | ||
|
||
@Unroll | ||
def 'wrappers "#name" exists'() { | ||
expect: | ||
node.buildWrappers[key].size() == 1 | ||
|
||
where: | ||
name | key | ||
'preBuildCleanup' | 'hudson.plugins.ws__cleanup.PreBuildCleanup' | ||
'injectPasswords' | 'EnvInjectPasswordWrapper' | ||
'maskPasswords' | 'com.michelin.cio.hudson.plugins.maskpasswords.MaskPasswordsBuildWrapper' | ||
'sshAgent' | 'com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper' | ||
} | ||
|
||
@Unroll | ||
def 'wrappers sshAgent with "#sshCredentials" value chosen'() { | ||
expect: | ||
node.buildWrappers['com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper'].size() == 1 | ||
|
||
with(node.buildWrappers['com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper']) { | ||
text() == sshCredentials | ||
} | ||
|
||
where: | ||
sshCredentials = "adop-jenkins-master" | ||
} | ||
|
||
def 'steps with two Maven blocks exists'() { | ||
expect: | ||
node.builders.size() == 1 | ||
|
||
with(node.builders[0]) { | ||
children().size() == 2 | ||
|
||
with(children()[0]) { | ||
name() == 'hudson.tasks.Maven' | ||
} | ||
} | ||
} | ||
|
||
@Unroll | ||
def 'step Maven target goal is "#goal"'() { | ||
expect: | ||
with(node.builders['hudson.tasks.Maven']) { | ||
targets.size() == 1 | ||
targets.text() == goal | ||
} | ||
|
||
where: | ||
goal = "clean install -DskipTests" | ||
} | ||
|
||
@Unroll | ||
def 'step Maven installation is "#installation" chosen'() { | ||
expect: | ||
with(node.builders['hudson.tasks.Maven']) { | ||
mavenName.size() == 1 | ||
mavenName.text() == installation | ||
} | ||
|
||
where: | ||
installation = "ADOP Maven" | ||
} | ||
|
||
def 'scm block with settings exists'() { | ||
expect: | ||
node.scm.size() == 1 | ||
|
||
with(node.scm) { | ||
userRemoteConfigs.size() == 1 | ||
|
||
with(userRemoteConfigs[0]) { | ||
children().size() == 1 | ||
|
||
with(children()[0]) { | ||
name() == 'hudson.plugins.git.UserRemoteConfig' | ||
} | ||
} | ||
} | ||
} | ||
|
||
def 'scm remote name is not specified'() { | ||
expect: | ||
with(node.scm.userRemoteConfigs[0].children()[0]) { | ||
name.size() == 0 | ||
} | ||
} | ||
|
||
@Unroll | ||
def 'scm remote url is "#referenceAppGitUrl"'() { | ||
expect: | ||
with(node.scm.userRemoteConfigs[0].children()[0]) { | ||
url.size() == 1 | ||
|
||
with(url) { | ||
text() == referenceAppGitUrl | ||
} | ||
} | ||
|
||
where: | ||
referenceAppGitUrl = "ssh://jenkins@gerrit:29418/${helper.projectName}/spring-petclinic" | ||
} | ||
|
||
@Unroll | ||
def 'scm credentials specified as "#gitCredentials"'() { | ||
expect: | ||
with(node.scm.userRemoteConfigs[0].children()[0]) { | ||
credentialsId.size() == 1 | ||
|
||
with(credentialsId) { | ||
text() == gitCredentials | ||
} | ||
} | ||
|
||
where: | ||
gitCredentials = "adop-jenkins-master" | ||
} | ||
|
||
@Unroll | ||
def 'scm branch is "#branchName"'() { | ||
expect: | ||
with(node.scm) { | ||
branches.size() == 1 | ||
branches['hudson.plugins.git.BranchSpec'].text() == branchName | ||
} | ||
|
||
where: | ||
branchName = '*/master' | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can replace this with DSL, instead of just XML fallback https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.publisher.PublisherContext.dependencyCheck