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

dz6r00yl  于 2022-11-01  发布在  Jenkins
关注(0)|答案(2)|浏览(244)

我想测试一下Jenkins的job-dsl作业,在job-dsl的官方版本库中有一个版本号已经过时的例子,所以我想用更新的版本实现同样的效果。
基于examplelinked存储库,我创建了以下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
}

但后来我得到了下面的错误,即使我定义了这个Trilead API插件的更新版本.也如果添加一些其他插件,将失败,因为他们有相互依赖,我怀疑出于某种原因,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)
cngwdvgl

cngwdvgl1#

从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'"
    }
}
vsnjm48y

vsnjm48y2#

对于任何在这方面遇到困难的人,这里有一个关于这个主题的Jenkins问题:https://issues.jenkins.io/browse/JENKINS-68216
我建议了一个适合我的解决方案。

相关问题