Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何解决Jenkins测试实例中的插件加载问题_Jenkins_Gradle_Groovy_Jenkins Job Dsl - Fatal编程技术网

如何解决Jenkins测试实例中的插件加载问题

如何解决Jenkins测试实例中的插件加载问题,jenkins,gradle,groovy,jenkins-job-dsl,Jenkins,Gradle,Groovy,Jenkins Job Dsl,我想测试用作业dsl编写的Jenkins作业,在官方作业dsl存储库中有一个例子,它的版本号已经过时。因此,我希望实现与示例中相同的功能,但使用较新的版本 基于和存储库,我创建了以下build.gradle文件 apply plugin: 'groovy' ext { jobDslVersion = '1.76' jenkinsVersion = '2.190.1' } sourceSets { jobs { groovy {

我想测试用作业dsl编写的Jenkins作业,在官方作业dsl存储库中有一个例子,它的版本号已经过时。因此,我希望实现与示例中相同的功能,但使用较新的版本

基于和存储库,我创建了以下build.gradle文件

apply plugin: 'groovy'

ext {
    jobDslVersion = '1.76'
    jenkinsVersion = '2.190.1'
}

sourceSets {
    jobs {
        groovy {
            srcDirs 'generators'
        }
    }
}

repositories {
    jcenter()
    mavenLocal()
    maven {
        url 'https://repo.jenkins-ci.org/public/'
    }
}

configurations {
    testPlugins {}

    // see JENKINS-45512
    testCompile {
        exclude group: 'xalan'
        exclude group: 'xerces'
    }
}

dependencies {
    compile "org.codehaus.groovy:groovy-all:2.5.7"
    compile "org.jenkins-ci.plugins:job-dsl-core:${jobDslVersion}"

    testCompile 'org.spockframework:spock-core:1.3-groovy-2.5'

    // Jenkins test harness dependencies
    testCompile 'org.jenkins-ci.main:jenkins-test-harness:2.56'
    testCompile "org.jenkins-ci.main:jenkins-war:${jenkinsVersion}"

    // Job DSL plugin including plugin dependencies

    testCompile "org.jenkins-ci.plugins:job-dsl:${jobDslVersion}"
    testCompile "org.jenkins-ci.plugins:job-dsl:${jobDslVersion}@jar"
    testCompile 'org.jenkins-ci.plugins:structs:1.20@jar'
    testCompile 'org.jenkins-ci.plugins:script-security:1.63@jar'
    testPlugins 'org.jenkins-ci.plugins:trilead-api:1.0.5@hpi'


    // plugins to install in test instance

    testPlugins 'org.jenkins-ci.plugins:credentials:2.3.0'
    testPlugins 'org.jenkins-ci.plugins:credentials-binding:1.12'

    testPlugins 'org.jenkins-ci.plugins:extra-columns:1.21'
    testPlugins 'org.jenkins-ci.plugins:mailer:1.20'
    testPlugins 'org.jenkins-ci.plugins:build-monitor-plugin:1.12+build.201809061734'

    testPlugins 'org.jenkins-ci.plugins:junit:1.28'
    testPlugins 'org.jenkins-ci.plugins:matrix-project:1.14'
    testPlugins 'org.jenkins-ci.plugins:groovy:2.2'
    testPlugins 'org.jenkins-ci.plugins:htmlpublisher:1.14'

    //testPlugins 'org.jenkins-ci.plugins:badge:1.8'
    testPlugins 'org.jvnet.hudson.plugins:groovy-postbuild:2.5'
    testPlugins 'org.jenkins-ci.plugins:ssh-credentials:1.18'

}

task resolveTestPlugins(type: Copy) {
    from configurations.testPlugins
    into new File(sourceSets.test.output.resourcesDir, 'test-dependencies')
    include '*.hpi'
    include '*.jpi'

    doLast {
        def baseNames = source.collect { it.name[0..it.name.lastIndexOf('.')-1] }
        new File(destinationDir, 'index').setText(baseNames.join('\n'), 'UTF-8')
    }
}

test {
    dependsOn tasks.resolveTestPlugins
    inputs.files sourceSets.jobs.groovy.srcDirs

    // set build directory for Jenkins test harness, JENKINS-26331
    systemProperty 'buildDirectory', project.buildDir.absolutePath
}
但是,即使我定义了这个TrileadAPI插件的较新版本,我还是出现了以下错误。另外,如果添加一些其他插件,由于它们相互依赖而失败,我怀疑出于某种原因Jenkins加载了这些插件的一些默认版本,这就是问题的原因。有没有办法打印出加载的插件版本?或者我该怎么做才能解决这个问题

java.io.IOException: SSH Credentials Plugin version 1.18 failed to load.
 - Trilead API Plugin version 1.0.4 is older than required. To fix, install version 1.0.5 or later.
    at hudson.PluginWrapper.resolvePluginDependencies(PluginWrapper.java:922)
    at hudson.PluginManager$2$1$1.run(PluginManager.java:545)
    at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169)
    at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296)
    at jenkins.model.Jenkins$5.runTask(Jenkins.java:1118)
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

从Jenkins脚本控制台获取所有插件版本的gradle样式列表

在下面输入并运行

Jenkins.instance.pluginManager.activePlugins.sort { it.shortName }.each { plugin ->     
    def manifest = plugin.manifest
    String groupId = manifest.mainAttributes.getValue('Group-Id')
    String artifactId = manifest.mainAttributes.getValue('Extension-Name')
    String version = manifest.mainAttributes.getValue('Implementation-Version')
    if (groupId && artifactId && version) {
        println "testPlugins '$groupId:$artifactId:$version'"
    }
}