Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
INT-431 Declarative pipeline support.
Browse files Browse the repository at this point in the history
  • Loading branch information
whyjustin committed Feb 13, 2018
1 parent 6ba7419 commit 2a3b185
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-definition</artifactId>
<version>1.2.7</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-standalone</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl
import org.kohsuke.stapler.AncestorInPath
import org.kohsuke.stapler.DataBoundConstructor
import org.kohsuke.stapler.DataBoundSetter
import org.kohsuke.stapler.QueryParameter

@ParametersAreNonnullByDefault
Expand All @@ -44,18 +45,26 @@ class IqPolicyEvaluatorWorkflowStep

String jobCredentialsId

@DataBoundSetter
public void setIqScanPatterns(final List<ScanPattern> iqScanPatterns) {
this.iqScanPatterns = iqScanPatterns
}

@DataBoundSetter
public void setFailBuildOnNetworkError(final Boolean failBuildOnNetworkError) {
this.failBuildOnNetworkError = failBuildOnNetworkError
}

@DataBoundSetter
public void setJobCredentialsId(final String jobCredentialsId) {
this.jobCredentialsId = jobCredentialsId
}

@DataBoundConstructor
IqPolicyEvaluatorWorkflowStep(final String iqStage,
final String iqApplication,
final List<ScanPattern> iqScanPatterns,
final Boolean failBuildOnNetworkError,
final String jobCredentialsId)
{
this.jobCredentialsId = jobCredentialsId
this.failBuildOnNetworkError = failBuildOnNetworkError
this.iqScanPatterns = iqScanPatterns
this.iqApplication = iqApplication
final String iqApplication) {
this.iqStage = iqStage
this.iqApplication = iqApplication
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,35 @@ class IqPolicyEvaluatorIntegrationTest
iqClientBuilder.build() >> iqClient
}

def 'Declarative pipeline build successful with mandatory parameters'() {
given: 'a jenkins project'
WorkflowJob project = jenkins.createProject(WorkflowJob)
configureJenkins()

when: 'the nexus policy evaluator is executed'
project.definition = new CpsFlowDefinition('' +
'pipeline { \n' +
'agent any \n' +
'stages { \n' +
'stage("Example") { \n' +
'steps { \n' +
'writeFile file: \'dummy.txt\', text: \'dummy\'\n' +
'nexusPolicyEvaluation failBuildOnNetworkError: false, iqApplication: \'app\', iqStage: \'stage\'\n' +
'} \n' +
'} \n' +
'} \n' +
'} \n')
def build = project.scheduleBuild2(0).get()

then: 'the application is scanned and evaluated'
1 * iqClient.scan(*_) >> new ScanResult(new Scan(), File.createTempFile('dummy-scan', '.xml.gz'))
1 * iqClient.evaluateApplication(*_) >>
new ApplicationPolicyEvaluation(0, 1, 2, 3, [], 'http://server/link/to/report')

and: 'the build is successful'
jenkins.assertBuildStatusSuccess(build)
}

def 'Pipeline build should return result when build is successful'() {
given: 'a jenkins project'
WorkflowJob project = jenkins.createProject(WorkflowJob)
Expand Down

0 comments on commit 2a3b185

Please sign in to comment.