[英]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.