Skip to content

Commit

Permalink
Add integration test for scanning Pipeline log
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfs committed Jun 22, 2019
1 parent 5000c8f commit ee10b95
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
16 changes: 14 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,25 @@ sourceCompatibility = '1.8'
dependencies {
jenkinsPlugins 'org.jenkins-ci.plugins:structs:1.5'
jenkinsPlugins 'org.jenkins-ci.plugins.workflow:workflow-api:2.20'
jenkinsPlugins 'org.jenkins-ci.plugins.workflow:workflow-cps:2.24'
jenkinsPlugins 'org.jenkins-ci.plugins.workflow:workflow-job:2.9'
jenkinsPlugins 'org.jenkins-ci.plugins.workflow:workflow-basic-steps:2.3'
jenkinsPlugins 'org.jenkins-ci.plugins.workflow:workflow-durable-task-step:2.8'
jenkinsPlugins 'org.jenkins-ci.plugins.workflow:workflow-step-api:2.10'

signature 'org.codehaus.mojo.signature:java18:1.0@signature'

jenkinsTest 'org.jenkins-ci.main:jenkins-test-harness:2.44'
jenkinsTest 'org.jenkins-ci.main:jenkins-test-harness:2.49'
jenkinsTest 'org.jenkins-ci.main:jenkins-test-harness-tools:2.2'
jenkinsTest 'io.jenkins:configuration-as-code:1.4'
jenkinsPlugins 'org.jenkins-ci.plugins.workflow:workflow-aggregator:2.6'

jenkinsServer 'org.jenkins-ci.plugins.workflow:workflow-aggregator:2.5'
jenkinsServer 'org.jenkins-ci.plugins.workflow:workflow-api:2.20'
jenkinsServer 'org.jenkins-ci.plugins.workflow:workflow-cps:2.24'
jenkinsServer 'org.jenkins-ci.plugins.workflow:workflow-job:2.9'
jenkinsServer 'org.jenkins-ci.plugins.workflow:workflow-basic-steps:2.3'
jenkinsServer 'org.jenkins-ci.plugins.workflow:workflow-durable-task-step:2.8'
jenkinsServer 'org.jenkins-ci.plugins.workflow:workflow-step-api:2.10'

testImplementation 'org.spockframework:spock-core:1.2-groovy-2.4'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import hudson.model.FreeStyleProject
import hudson.tasks.BatchFile
import hudson.tasks.Maven
import hudson.tasks.Shell
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition
import org.jenkinsci.plugins.workflow.job.WorkflowJob
import org.jvnet.hudson.test.CreateFileBuilder
import org.jvnet.hudson.test.ExtractResourceSCM
import org.jvnet.hudson.test.JenkinsRule
Expand Down Expand Up @@ -55,6 +57,42 @@ class BuildScanIntegrationTest extends AbstractIntegrationTest {
new URL(action.scanUrls.get(0))
}

def 'detects build scan in pipeline log'() {
given:
gradleInstallationRule.gradleVersion = '5.1'
gradleInstallationRule.addInstallation()
def pipelineJob = j.createProject(WorkflowJob)
pipelineJob.setDefinition(new CpsFlowDefinition("""
node {
def gradleHome
stage('Preparation') {
gradleHome = tool '${gradleInstallationRule.gradleVersion}'
}
stage('Build') {
// Run the maven build
if (isUnix()) {
sh 'touch settings.gradle'
sh "'\${gradleHome}/bin/gradle' help --scan"
} else {
bat(/"\${gradleHome}\\bin\\gradle.bat" help --scan/)
}
}
stage('Final') {
findBuildScans()
}
}
""", false))

when:
def build = pipelineJob.scheduleBuild2(0).get()

then:
println JenkinsRule.getLog(build)
def action = build.getAction(BuildScanAction)
action.scanUrls.size() == 1
new URL(action.scanUrls.get(0))
}

def 'build scan is discovered from Maven build'() {
given:
def p = j.createFreeStyleProject()
Expand Down

0 comments on commit ee10b95

Please sign in to comment.