jenkinsfile小试牛刀

本文主要演示一下如何用jenkinsfile来编译java服务

安装jenkins

这里使用docker来安装jenkins

复制代码
docker run --name jenkins-docker \
--volume $HOME/jenkins_home:/var/jenkins_home \
-p 8080:8080 jenkins/jenkins:2.416

之后访问http://${yourip}:8080,然后输入admin密码继续安装

jenkinsfile

复制代码
pipeline {
    agent any

    tools {
        // Install the Maven version configured as "M3" and add it to the path.
        maven "M3"
    }

    stages {
        stage('Build') {
            steps {
                // Get some code from a GitHub repository
                git 'https://github.com/jglick/simple-maven-project-with-tests.git'

                // Run Maven on a Unix agent.
                sh "mvn -Dmaven.test.failure.ignore=true clean package"

                // To run Maven on a Windows agent, use
                // bat "mvn -Dmaven.test.failure.ignore=true clean package"
            }

            post {
                // If Maven was able to run the tests, even if some of the test
                // failed, record the test results and archive the jar file.
                success {
                    junit '**/target/surefire-reports/TEST-*.xml'
                    archiveArtifacts 'target/*.jar'
                }
            }
        }
    }
}

这里定义了Build,它先是git拉取代码,然后执行mvn进行编译,最后在post部分在状态为success时使用junit显示测试报告,并归档jar包

小结

jenkins2.x提供了pipeline as code的功能,可以通过jenkinsfile(类似gitlab ci yaml),使用dsl来定义流水线,这个相比于在界面上配置更为易用和清晰,也容易进行版本化管理。

doc

相关推荐
凤舞飘伶4 分钟前
jenkins问题处理方法
jenkins
lbb 小魔仙7 小时前
告别腾讯会议40分钟限制:用ToDesk协作版开在线会议,免费不限时远程会议新方案
python·langchain·jenkins
恼书:-(空寄10 小时前
从手动部署到一键发版:Java项目CI/CD流水线搭建实录
ci/cd·jenkins·流水线部署
星梦清河11 小时前
微服务-Elasticsearch02
微服务·架构·jenkins
终端行者11 小时前
Jenkins Pipeline 构建后推送到Nexus制品库 jenkins 如何连接Nexus?企业级实战 --中 Jenkins 连接Nexus 实战
运维·ci/cd·docker·jenkins·nexus
隔窗听雨眠11 小时前
一份完整的Jenkins故障排查指南
jenkins
终端行者11 小时前
Jenkins Pipeline 构建后推送到Nexus制品库 jenkins 如何连接Nexus?企业级实战 --上 Nexus部署
运维·ci/cd·jenkins·nexus
小闫BI设源码1 天前
当20个节点选出两个Master时:Elasticsearch的致命故障与解决方案
java·elasticsearch·jenkins·php·面试宝典·深入解析
醉颜凉1 天前
Elasticsearch 核心原理:Posting List 倒排列表深度详解
大数据·elasticsearch·jenkins
牛奶咖啡131 天前
CI/CD——在jenkins中构建流程实现springboot项目的自动化构建与部署
java·ci/cd·k8s·jenkins·springboot·springboot制作镜像·使用源码项目制作镜像