nev*_*ves 3 maven jenkins jenkins-pipeline
Jenkins Pipeline 共享库通常具有以下目录结构:
(root)
+- src # Groovy source files
| +- org
| +- foo
| +- Bar.groovy # for org.foo.Bar class
+- vars
| +- foo.groovy # for global 'foo' variable
| +- foo.txt # help for 'foo' variable
+- resources # resource files (external libraries only)
| +- org
| +- foo
| +- bar.json # static helper data for org.foo.Bar
Run Code Online (Sandbox Code Playgroud)
这些是 grovvy 文件,使用 Jenkins 库中的一些代码。我希望能够使用 maven 编译它们,可能使用GMavenPlus maven 插件,并定义一些 Jenkins 库作为依赖项。
我想然后编译,以便我可以在提交或上传到 Jenkins 之前验证文件。我可能还会在编辑文件时提供更好的代码完成功能。
有人可以帮我创建一个可以编译它的 pom.xml 文件吗?
我建议使用 Gradle 而不是 Maven。下面你可以找到一个最小build.gradle文件,它允许你编译、测试和打包 Jenkins 共享库(如果需要与其他项目共享,甚至可以安装在 Maven 存储库中):
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'maven'
repositories {
mavenCentral()
}
sourceSets {
main {
groovy {
srcDirs = ['src', 'vars']
}
resources {
srcDirs = ['resources']
}
}
test {
groovy {
srcDirs = ['test']
}
}
}
dependencies {
compile 'com.cloudbees:groovy-cps:1.22'
compile 'org.codehaus.groovy:groovy-all:2.4.12'
// https://github.com/jenkinsci/JenkinsPipelineUnit
testCompile 'com.lesfurets:jenkins-pipeline-unit:1.1'
testCompile 'junit:junit:4.12'
}
jacocoTestReport {
reports {
xml.enabled true
}
}
Run Code Online (Sandbox Code Playgroud)
这个最小的build.gradle文件使用jenkins-pipeline-unit- Jenkins 管道的单元测试框架。它非常方便,让生活轻松十倍。
或者,您可以检查以下 Jenkins Pipeline 共享库的 Gradle 模板项目 - https://github.com/mkobit/jenkins-pipeline-shared-library-example它具有许多其他功能,并且还有助于维护您的共享库项目。
但是,如果您确实需要为此使用 Maven,则可以使用以下命令pom.xml:
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'maven'
repositories {
mavenCentral()
}
sourceSets {
main {
groovy {
srcDirs = ['src', 'vars']
}
resources {
srcDirs = ['resources']
}
}
test {
groovy {
srcDirs = ['test']
}
}
}
dependencies {
compile 'com.cloudbees:groovy-cps:1.22'
compile 'org.codehaus.groovy:groovy-all:2.4.12'
// https://github.com/jenkinsci/JenkinsPipelineUnit
testCompile 'com.lesfurets:jenkins-pipeline-unit:1.1'
testCompile 'junit:junit:4.12'
}
jacocoTestReport {
reports {
xml.enabled true
}
}
Run Code Online (Sandbox Code Playgroud)
这或多或少相当于该build.gradle文件。
| 归档时间: |
|
| 查看次数: |
2553 次 |
| 最近记录: |