简体   繁体   English

Jenkins Pipeline - Workflow CPS插件JAR依赖项

[英]Jenkins Pipeline - Workflow CPS plugin JAR dependencies

I'm implementing unit tests for code used in a Jenkins Pipeline Shared Groovy Library . 我正在为Jenkins Pipeline Shared Groovy Library中使用的代码实现单元测试。 Specically, I need to mock the steps object available in the Jenkinsfile, which is an instance of org.jenkinsci.plugins.workflow.cps.DSL . 特别是,我需要模拟Jenkinsfile中可用的steps对象,它是org.jenkinsci.plugins.workflow.cps.DSL一个实例。 In my Gradle build I've specified a dependency like so: 在我的Gradle构建中,我已经指定了一个依赖项,如下所示:

testCompile group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-cps', version: '2.30', ext: 'jar'

which is the project hosting the class above. 这是主持上述课程的项目。 Without specifying the ext as a JAR, Gradle retrieves the .hpi file since this is the packaging defined in the project's pom.xml; 如果不将ext指定为JAR,Gradle将检索.hpi文件,因为这是项目的pom.xml中定义的包。 obviously I need to override this and fetch the JAR for my project. 显然我需要覆盖它并为我的项目获取JAR。 However, in doing this Gradle does not download the transitive dependencies of the workflow-cps JAR and I find myself having to populate my build.gradle with all the dependencies determined via trial and error. 但是,在执行此操作时,Gradle不会下载workflow-cps JAR的传递依赖项,并且我发现自己必须使用通过反复试验确定的所有依赖项来填充我的build.gradle。 Is there a way to retrieve the transitive dependencies, or is this a limitation of the workflow-cps project and how it defines its pom.xml? 有没有办法检索传递依赖项,或者这是workflow-cps项目的限制以及它如何定义其pom.xml?

The CPS class you're wanting to mock won't contain methods/variables introduced by plugins or your workflow lib, so this approach probably won't be fully satisfying. 您想要模拟的CPS类不包含插件或工作流库引入的方法/变量,因此这种方法可能不会完全令人满意。

Facing the same challenge I took the pragmatic approach of making my own TestScript interface in my test sources and Mock that, and not typing the script reference in classes. 面对同样的挑战,我采取了实用的方法,在我的测试源和Mock中创建自己的TestScript接口,而不是在类中键入脚本引用。

The drawbacks are not having IDE code inspection for stuff referencing the script, and having to manually add signatures to TestScript as I add tests (which is also error-prone, since I have manually ensure that those signatures match). 缺点是没有对引用脚本的东西进行IDE代码检查,并且在添加测试时不得不手动将签名添加到TestScript(这也很容易出错,因为我手动确保这些签名匹配)。

But it works, and avoids getting dragged into plugin dependency hell. 但它有效,并避免被拖入插件依赖地狱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Jenkins工作流/管道中的插件提供的功能 - Using the features provided by a plugin in a Jenkins workflow/pipeline Jenkins构建流程与工作流程(管道)插件 - Jenkins Build Flow versus Workflow (Pipeline) plugin Jenkins Pipeline插件—获取和建立依赖关系 - Jenkins Pipeline Plugin — getting and building dependencies 从 Jenkins Workflow (Pipeline) Plugin 获取登录用户名 Jenkins - Get username logged in Jenkins from Jenkins Workflow (Pipeline) Plugin 詹金斯管道CPS问题与并行作业 - Jenkins pipeline CPS issue with parallel jobs Jenkins 管道中的 PowerShell 环境变量给出了`org.jenkinsci.plugins.workflow.cps.EnvActionImpl@1b69f5bb:VARIABLE_NAME` - PowerShell environment variable in Jenkins Pipeline gives `org.jenkinsci.plugins.workflow.cps.EnvActionImpl@1b69f5bb:VARIABLE_NAME` Jenkins工作流(管道)+ JobDSL插件-SCM不起作用 - Jenkins workflow (pipeline) + JobDSL plugin - SCM does not work 如何在Jenkins工作流(管道)插件中执行作业dsl脚本 - How to execute job dsl script in Jenkins workflow (pipeline) plugin Groovy沙箱阻止workflow-cps-global-lib-plugin中的类 - Groovy sandbox blocks classes in workflow-cps-global-lib-plugin Jenkins 2 - 如何从 Jenkins Workflow - Pipeline Plugin 获取用户角色(角色策略插件) - Jenkins 2 - How to get user role (Role Strategy Plugin) from Jenkins Workflow - Pipeline Plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM