无法加载JenkinsPipelineSpecification,因为缺少依赖项。

huangapple go评论51阅读模式
英文:

Failing to load JenkinsPipelineSpecification due to missing dependency

问题

I am trying to write a small groovy test file using Spock framework to load the Jenkinsfile.

I am trying to write some unit tests to verify if Jenkinsfile is working as expected
And also use these unit tests to see any update to Jenkinsfile is not breaking any

Below is my Jenkins tests file

package tests.library

import com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification

public class JenkinsfileWithPropertySpec extends JenkinsPipelineSpecification {

       protected Script Jenkinsfile

       def setup() {
           Jenkinsfile = loadPipelineScriptForTest("pipelineConfig/Jenkinsfile")
       }

       def "Jenkinsfile"() {
           when:
                Jenkinsfile.run()
           then:
                1 * getPipelineMock("node")("legacy", _)
                1 * getPipelineMock("echo")("hello world")
        }
}

When i try run it with gradle it fails with error:

$ ~/source/gradle/gradle-8.0.2/bin/gradle clean test 
> Task :compileTestGroovy FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileTestGroovy'.
> Unable to load class com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification due to missing dependency Ljenkins/model/Jenkins;

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org
BUILD FAILED in 1s
2 actionable tasks: 2 executed

My build.gradle consists of below:

apply plugin: 'groovy'

repositories {
    mavenCentral()
}

dependencies {
   testImplementation 'junit:junit:4.13'
   testImplementation 'org.codehaus.groovy:groovy-all:2.4.14'
   testImplementation 'org.spockframework:spock-core:1.1-groovy-2.4'
   testImplementation 'com.lesfurets:jenkins-pipeline-unit:1.1'
   testImplementation 'cglib:cglib-nodep:3.2.2'
   testImplementation 'org.objenesis:objenesis:1.2'
   testImplementation 'org.assertj:assertj-core:3.7.0'
   testImplementation 'com.homeaway.devtools.jenkins:jenkins-spock:2.1.5'
}

sourceSets {

    test {
        groovy {
            srcDirs= ['pipelineTests/groovy']
        }
    }
}

Any pointers what i am doing wrong. Thanks

英文:

I am trying to write a small groovy test file using Spock framework to load the Jenkinsfile.

I am trying to write some unit tests to verify if Jenkinsfile is working as expected
And also use these unit tests to see any update to Jenkinsfile is not breaking any

Below is my Jenkins tests file

package tests.library

import com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification

public class JenkinsfileWithPropertySpec extends JenkinsPipelineSpecification {

       protected Script Jenkinsfile

       def setup() {
           Jenkinsfile = loadPipelineScriptForTest("pipelineConfig/Jenkinsfile")
       }

       def "Jenkinsfile"() {
           when:
                Jenkinsfile.run()
           then:
                1 * getPipelineMock("node")("legacy", _)
                1 * getPipelineMock("echo")("hello world")
        }
}

When i try run it with gradle it fails with error:

$ ~/source/gradle/gradle-8.0.2/bin/gradle clean test 
> Task :compileTestGroovy FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileTestGroovy'.
> Unable to load class com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification due to missing dependency Ljenkins/model/Jenkins;

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org
BUILD FAILED in 1s
2 actionable tasks: 2 executed

My build.gradle consists of below:

apply plugin:   'groovy'

repositories {
    mavenCentral()
}

dependencies {
   testImplementation 'junit:junit:4.13'
   testImplementation 'org.codehaus.groovy:groovy-all:2.4.14'
   testImplementation 'org.spockframework:spock-core:1.1-groovy-2.4'
   testImplementation 'com.lesfurets:jenkins-pipeline-unit:1.1'
   testImplementation 'cglib:cglib-nodep:3.2.2'
   testImplementation 'org.objenesis:objenesis:1.2'
   testImplementation 'org.assertj:assertj-core:3.7.0'
   testImplementation 'com.homeaway.devtools.jenkins:jenkins-spock:2.1.5'
}

sourceSets {

    test {
        groovy {
            srcDirs= ['pipelineTests/groovy']
        }
    }
}

Any pointers what i am doing wrong. Thanks

答案1

得分: 1

It looks like you're missing the jenkins-core dependency. According to the jenkins-spock documentation:

There are some dependencies of this library that are marked with Maven's provided scope. This means that Maven will pull them in for building and testing this library, but when you use this library, you must pull those libraries in as dependencies yourself.

Among those libraries, there is jenkins-core, the library that contains the jenkins.model.Jenkins class that your build cannot find.

Please try to add the jenkins-core dependency to your file and check if it solves the problem.

英文:

It looks like you're missing jenkins-core dependency. According to the jenkins-spock documentation:

> There are some dependencies of this library that are marked with Maven's provided scope. This means that Maven will pull them in for building and testing this library, but when you use this library you must pull those libraries in as dependencies yourself.

Among those libraries there is a jenkins-core, the library that contains jenkins.model.Jenkins class that your build can not find.

Pleas try to add the jenkins-core dependency to your file and check if it solves the problem.

huangapple
  • 本文由 发表于 2023年4月10日 23:43:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75978532.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定