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

相关推荐
一点晖光8 小时前
jenkins优化记录
运维·jenkins
成为你的宁宁21 小时前
【基于 GitLab Webhook 的 Jenkins 自动触发构建实现手册:涵盖概念原理、环境配置、故障处理及 Tag/Commit 维度参数化构建实践】
自动化·gitlab·jenkins
朱 欢 庆1 天前
Jenkins任务执行完成后发送邮件
前端·经验分享·jenkins
成为你的宁宁1 天前
【Jenkins添加钉钉通知】
jenkins·钉钉
Filotimo_1 天前
在java后端开发中,ES的用处
java·elasticsearch·jenkins
回吐泡泡oO1 天前
ElasticSearch添加登录校验(仅供参考)
java·elasticsearch·jenkins
Lynnxiaowen1 天前
今天我们继续DevOps内容Jenkins自动化部署PHP项目
linux·自动化·jenkins·php·devops
云和数据.ChenGuang2 天前
Logstash配置文件的**语法解析错误**
运维·数据库·分布式·rabbitmq·jenkins
11小猪会飞112 天前
.net使用Jenkins 构建、部署到windows服务器上
运维·jenkins
一条懒鱼6662 天前
Jenkins 2.528.3 与 GitLab 深度集成:实现自动构建
servlet·gitlab·jenkins