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

相关推荐
[奋斗不止]4 小时前
Jenkins 构建 Unity 打包 .apk 同时生成 .aab
jenkins·jenkins 打包 .aab·jenkins导出aab·jenkisn 导出 apk
boy快快长大4 小时前
【Elasticsearch】同一台服务器部署集群
服务器·elasticsearch·jenkins
深情不及里子5 小时前
纯手工搭建整套CI/CD流水线指南
ci/cd·gitlab·jenkins·harbor
梁萌5 小时前
04-DevOps-安装并初始化Jenkins
运维·jenkins·devops
跳跳的向阳花6 小时前
06、ElasticStack系列,第六章:elasticsearch设置密码
大数据·elasticsearch·jenkins
枫叶落雨22217 小时前
08-Elasticsearch
运维·jenkins
web150854159351 天前
Spring Boot(十六):使用 Jenkins 部署 Spring Boot
spring boot·后端·jenkins
m0_748255021 天前
Springboot中使用Elasticsearch(部署+使用+讲解 最完整)
spring boot·elasticsearch·jenkins
[奋斗不止]1 天前
Jenkins 视图(View)
jenkins·jenkins视图view·jenkins 视图view
Karoku0661 天前
【CI/CD】Jenkinsfile管理+参数化构建+邮件通知以及Jenkins + SonarQube 代码审查
运维·ci/cd·容器·kubernetes·jenkins·rancher