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

相关推荐
mylove_北极甜虾4 天前
jenkins-01Jenkins 架构与任务调度
运维·jenkins
筑梦之人7 天前
Elasticsearch 9.x 从入门到精通(4/7):聚合分析与文本分析
大数据·elasticsearch·jenkins
风翼靓崽10 天前
jenkins搭建与简单使用
运维·jenkins
小白的码BUG之路10 天前
Jenkins -- gitee+docker+harbor+k8s 部署项目
docker·gitee·jenkins
RuoyiOffice13 天前
KubeSphere 容器云实践:从管理 K8s 到建设企业 PaaS,还需要哪些能力
spring boot·kubernetes·kubesphere·jenkins·paas·微服务部署·ruoyi office
@兽血沸腾15 天前
Windows系统安装Jenkins部署应用至远程Windows服务器操作指南
运维·服务器·jenkins
拖累斯16 天前
Jenkins + Python 全自动跑通「禅道任务/BUG 导出 → 月度开发考核表」
python·jenkins·bug
逐流人16 天前
DevOps 入门实战(一):从 CI/CD 概念到 Jenkins 自动构建部署
运维·云原生·云计算·jenkins·devops
修心光19 天前
记录一次,jenkins打包异常问题
运维·jenkins
后台模板学习19 天前
GitHub Actions 与 Jenkins 在日志监
运维·github·jenkins