编译groovy项目并通过Jenkins运行JUnit测试

问题描述 投票:1回答:1

我现在用Google搜索了很多年,我放弃了,热门话题Groovy + Jenkins正在提出这么多假旗......

我有一个我在IntelliJ中开发的Groovy项目,它还包含一个带单元测试的JUnit.groovy。现在这是SoapUI的脚本,不需要Maven,Ant或Grails,但我希望能够在Jenkins上编译这些文件并在之后运行单元测试。是否可以在Jenkins上构建和测试这些文件?到目前为止,所有解决方案似乎都是我手动运行groovyc(与我的存储库一起提交),然后在JUnit.class上运行JUnit。

所以在我开始深入挖掘并编写Maven,Grails或Ant文件之前,还有另一种方法不涉及我在我的git上推动GroovySDK吗?或者是否可能有一个简单的构建脚本,不涉及20个库和步骤来构建groovy源并运行JUnit测试:)?

我显然是詹金斯的新手;),感谢你的投入。

更新:

  • 所以作为新手和我一样,需要什么?首先我将本地源代码更改为gradle项目(记得在IntelliJ中激活AutoImport)并激活JUnit xml的创建,因为我不使用Maven并且系统处于“离线”状态,所以我们在git中都有libs所以我的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 wrappergradlew.bat设置项目的gradle包装
  • 然后我在我的git-post-commit中添加了一个/.hooks/,所以我的詹金斯是通过curl http://jenkins:8080/git/notifyCommit?url=https://git.git&branches=dev提交时触发的
  • 最后在jenkins上建立了一个管道: #!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" }
jenkins gradle groovy junit
1个回答
2
投票

有一个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,只需声明依赖项。

© www.soinside.com 2019 - 2024. All rights reserved.