如何在 jenkins 中使用 gradle 编译 @Library @NonCPS

Tin*_*vec 3 groovy shared-libraries gradle jenkins jenkins-pipeline

我需要验证管道脚本(脚本化管道)中的代码更改,但是我在编译 @Library 和 @NonCPS 行时遇到了问题。

在 gradle 中执行任务编译时,出现错误:

unable to resolve class Library ,  unable to find class for annotation @Library('someLibrary') _

unable to resolve class NonCPS ,  unable to find class for annotation @NonCPS
Run Code Online (Sandbox Code Playgroud)

我尝试在依赖项中包含一些外部插件,如下所示:

dependencies {
    compile 'org.jenkins-ci.plugins.workflow:workflow-cps:2.41@jar'
    compile 'org.jenkins-ci.plugins.workflow:workflow-cps-global-lib:2.4@jar'
    compile 'org.jenkins-ci.plugins:pipeline-utility-steps:1.5.0@jar'
    compile 'org.jenkins-ci.plugins.workflow:workflow-support:2.14@jar'
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    compile "org.jenkins-ci.plugins:job-dsl-core:${jobDslPluginVersion}"
    compile 'org.jenkins-ci.main:jenkins-core:1.609.3'
    compile 'org.jenkins-ci.plugins:build-pipeline-plugin:1.5.6'
    compile 'org.jenkins-ci.plugins:pipeline-build-step:2.5.1'
    compile 'org.jenkins-ci.plugins.pipeline-stage-view:pipeline-stage-view:2.9'
    compile 'org.jenkins-ci.plugins.workflow:workflow-cps:2.41'
    compile 'org.jenkins-ci.plugins.workflow:workflow-cps-global-lib:2.4'
    compile 'org.jenkins-ci.plugins:pipeline-utility-steps:1.5.0'
    compile 'org.jenkins-ci.plugins.workflow:workflow-support:2.14'
}
Run Code Online (Sandbox Code Playgroud)

但没有按预期工作。

我是 gradle 新手,所以我可能会错过一些理解。

mko*_*bit 6

NonCPS注释类型来自开源的CloudBees / Groovy的厘泊在包存储库com.cloudbees.groovy.cps

您可以在诸如compile('com.cloudbees:groovy-cps:1.22').