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

相关推荐
biaov2 天前
Jenkins + Docker 搭建前端 CI:前端一键打包部署
前端·docker·jenkins
kaixin_learn_qt_ing5 天前
Jenkins
运维·jenkins
Madison-No75 天前
Jenkins持续集成
运维·ci/cd·jenkins
boy快快长大6 天前
【Jenkins】入门学习
运维·学习·jenkins
oioihoii7 天前
Jenkins自动部署全流程:CentOS 7、GitHub、Gitee、GitLab、Vue+Maven与Webhook
centos·github·jenkins
Geek-Chow7 天前
Building and Using a Jenkins Shared Library
jenkins
flytalei8 天前
逐浪笔记 GitOps 实战:Jenkins 构建、Argo CD 同步与 Git 回滚
笔记·git·jenkins
flytalei8 天前
从 Jenkins 到 Argo CD:搭建一条完整的 GitOps 实战链路
运维·jenkins
你看我名字9 天前
LAMP 架构演练:从云主机准备到 Apache、PHP、MySQL 上线验证
运维·ci/cd·架构·kubernetes·jenkins
成为你的宁宁9 天前
【基于 SSH 与 JNLP 协议的 Jenkins 分布式构建方案】
分布式·jenkins