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

相关推荐
wan_da_ren8 小时前
Docker安装Elasticsearch9.2.1与Kibana9.2.1 保姆教程(带验证版)
运维·docker·jenkins
要站在顶端15 小时前
基于 curl 实现 Jenkins 上传制品到 JFrog Artifactory
运维·ci/cd·jenkins
小安同学iter1 天前
三台服务器,一套流水线:如何实现无缝自动化部署?
gitlab·jenkins
...对方正在输入......2 天前
Elasticsearch集群部署实战指南
elasticsearch·jenkins
程序员潇潇2 天前
Jenkins 插件下载速度慢安装失败?这篇文章可能解决你头等难题!
运维·自动化测试·软件测试·功能测试·程序人生·职场和发展·jenkins
ζั͡山 ั͡有扶苏 ั͡✾2 天前
EFK 日志系统搭建完整教程
运维·jenkins·kibana·es·filebeat
小晶晶京京3 天前
day62-gitlab和JenKins
运维·gitlab·jenkins
奔跑吧邓邓子3 天前
Jenkins自动化持续集成:从入门到实战
ci/cd·自动化·实战·jenkins·自动化持续集成
e***0964 天前
Springboot中使用Elasticsearch(部署+使用+讲解 最完整)
spring boot·elasticsearch·jenkins
Better Bench4 天前
Elasticsearch BM25 检索器连接问题解决方案
大数据·elasticsearch·jenkins