我用谷歌搜索了很长时间然后我放弃了,流行词 Groovy + Jenkins 带来了很多错误的标志......
我有一个在 IntelliJ 中开发的 Groovy 项目,它还包含一个带有单元测试的 JUnit.groovy。现在这是 SoapUI 的脚本,不需要 Maven、Ant 或 Grails,但我希望能够在 Jenkins 上编译这些文件并在之后运行单元测试。是否可以在 Jenkins 上构建和测试这些文件?到目前为止,所有解决方案似乎都是我手动运行 groovyc(与我的存储库一起提交),然后在 JUnit.class 上运行 JUnit。
因此,在我开始深入挖掘并编写 Maven、Grails 或 Ant 文件之前,是否有另一种方法不涉及在我的 git 上推送 GroovySDK?或者是否有一个简单的构建脚本,不涉及 20 个库和步骤来构建 groovy 源代码并运行 JUnit 测试:)?
我显然是 Jenkins 的新手 ;),感谢您的意见。
更新:
build.gradle
是:version '2.5-SNAPSHOT'
apply plugin: 'groovy'
dependencies {
compile fileTree(dir: '../Library', include: ['*.jar'])
}
test {
reports {
junitXml.enabled = true
html.enabled = true
}
}
sourceCompatibility = 1.8
gradle wrapper
为项目设置 gradle 包装器对于gradlew.bat
post-commit
在我的 git-/.hooks/
所以我的 Jenkins 在通过 curl http://jenkins:8080/git/notifyCommit?url=https://git.git&branches=dev
提交时被触发#!groovy
node {
stage('Checkout') {
git branch: 'dev', credentialsId: 'youwish', url: 'https://git.git'
}
stage('Build') {
dir('./Modules') {
gradle('clean')
gradle('compileTestGroovy')
}
}
stage('UnitTest') {
dir('./Modules') {
gradle('test')
junit '/build/test-results/**/TEST-*.xml'
}
}
stage('IntegrationTest') {
stage('CodeTableDownload') {
dir('./SoapUi') {
bat 'AutoRun.bat'
junit '/results/**/*-JUNIT.xml'
}
}
}
}
def gradle(command) {
bat "./gradlew.bat $command"
}
最佳答案
有一个Groovy plugin for Jenkins这将让您在 Jenkins 上执行 Groovy 脚本。
但是,为什么不让 Gradle 之类的东西为您构建并运行测试呢? Groovy 的最小 Gradle 构建文件可以同时执行这两种操作:
apply plugin: 'groovy'
repositories {
jcenter()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.12'
testCompile 'junit:junit:4.12'
}
您不必提交 GDK,只需声明一个依赖项。
关于jenkins - 编译 groovy 项目并通过 Jenkins 运行 JUnit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47928927/