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

相关推荐
qq_3494479519 小时前
jenkin节点创建
jenkins
飞翔的熊blabla2 天前
# Webpack 5 + Jenkins 持久化缓存实战:前端构建从 288 秒降到 30 秒>
前端·webpack·jenkins
海兰4 天前
Elasticsearch ES|QL:让全文本搜索无处不在
大数据·elasticsearch·jenkins
IT界的老黄牛4 天前
Jenkins 监控一条龙:接入、看板 9964、11 条告警规则直接抄走
jenkins·grafana·prometheus·监控·ci-cd·告警规则
小袁拒绝摆烂4 天前
Jenkins部署经验
运维·jenkins
IT界的老黄牛5 天前
Jenkins 构建卡了 23 天,abort 按钮点了没用
jenkins·maven·prometheus·告警·排查·ci-cd
GGG7667 天前
K8s1.28 全栈落地|Jenkins+GitLab+Harbor DevOps 流水线封神实战
kubernetes·gitlab·jenkins
叱咤少帅(少帅)8 天前
新版本jenkins的共享库的实现
运维·jenkins
2601_962297258 天前
Python、Pytest、Allure、Selenium和Jenkins实现自动化测试集成实例
python·selenium·jenkins·pytest·allure
大模型丫丫8 天前
工业级 RAG 为什么需要 Elasticsearch?
elasticsearch·django·jenkins