轻量级前端框架助力开发者提升项目效率与性能
680
2022-09-27
Jenkins 常用的项目构建工具集成 02 Gradle
gradle相对于maven项目来说,打包速度会快一些(这个工具也需要Java的环境)和之前maven创建项目一样,这个不变。
-gradle构建工具
创建gradle项目
将项目推送到gitlab上面
[root@jenkins-master ~]# cd devops-gradle-service-master[root@jenkins-master devops-gradle-service-master]# lsbuild.gradle gradle gradlew gradlew.bat Jenkinsfile settings.gradle src[root@jenkins-master devops-gradle-service-master]# git initInitialized empty Git repository in /root/devops-gradle-service-master/.git/[root@jenkins-master devops-gradle-service-master]# git remote add origin devops-gradle-service-master]# git add .[root@jenkins-master devops-gradle-service-master]# git commit -m "Initial commit"[master (root-commit) eef0e43] Initial commit 11 files changed, 475 insertions(+) create mode 100644 .gitignore create mode 100644 Jenkinsfile create mode 100644 build.gradle create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle create mode 100644 src/main/java/com/example/demo/DemoApplication.java create mode 100644 src/main/resources/application.properties create mode 100644 src/test/java/com/example/demo/DemoApplicationTests.java[root@jenkins-master devops-gradle-service-master]# git push -u origin masterUsername for 'rootPassword for 'Counting objects: 27, done.Compressing objects: 100% (16/16), done.Writing objects: 100% (27/27), 58.48 KiB | 0 bytes/s, done.Total 27 (delta 0), reused 0 (delta 0)To * [new branch] master -> masterBranch master set up to track remote branch master from origin.
安装配置
unzip gradle-6.8.3-bin.zip -d /usr/local/export GRADLE_HOME=/usr/local/gradle-6.8.3/export PATH=$GRADLE_HOME/bin:$PATHgradle -v
gradle项目的构建
常用命令
gradle build 构建项目gradle build -x test 构建项目跳过测试gradle clean 清空构建目录
我们这里使用远程的Jenkinsfile,也就是将Jenkinsfile存放在远程的版本系统里面,添加一个Jenkinsfile
配置仓库地址
配置SCM这里会多出代码-的步骤
现在要跳过这个阶段,下面生成代码
options { skipDefaultCheckout true}
gradle在build的时候会去做测试,gradle buid会去做测试,如果gradle build -x test就会跳过测试
[root@jenkins-master devops-gradle-service-master]# gradle buildStarting a Gradle Daemon (subsequent builds will be faster)> Task :test2021-06-02 14:52:43.469 INFO 9119 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'BUILD SUCCESSFUL in 3m 13s6 actionable tasks: 6 executed#测试报告的位置[root@jenkins-master devops-gradle-service-master]# lsbuild build.gradle gradle gradlew gradlew.bat Jenkinsfile settings.gradle src[root@jenkins-master devops-gradle-service-master]# cd build[root@jenkins-master build]# lsbootJarMainClassName classes generated libs reports resources test-results tmp[root@jenkins-master build]# cd test-results/[root@jenkins-master test-results]# lstest[root@jenkins-master test-results]# cd test/[root@jenkins-master test]# lsbinary TEST-com.example.demo.DemoApplicationTests.xml#包的位置[root@jenkins-agent build]# ls libs/demo-0.0.1-SNAPSHOT.jar[root@jenkins-agent build]# pwd/root/devops-gradle-service-master/build
def buildTools = ["gradle": "/usr/local/gradle-6.8.3"]pipeline{ agent {label "build"} options { skipDefaultCheckout true} stages{ stage("GetCode"){ steps{ script{ println("-分支代码----->${env.branchName}") checkout([$class: 'GitSCM', branches: [[name: "${env.branchName}"]], extensions: [], userRemoteConfigs: [[credentialsId: '1d2790c6-c757-4011-8348-c4e91ce26ea9', url: "${env.gitHttpURL}"]]]) } } } stage("Build"){ steps{ script{ sh "${buildTools["gradle"]}/bin/gradle clean && ${buildTools["gradle"]}/bin/gradle build -x test" } } } stage("UnitTest"){ steps{ script{ sh "${buildTools["gradle"]}/bin/gradle test" } } post{ success{ script{ junit 'build/test-results/test/*.xml' } } } } }}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~