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

相关推荐
橙*^O^*安4 小时前
Kubernetes集群部署Jenkins指南
云原生·容器·kubernetes·jenkins·devops
刘一说7 小时前
Elasticsearch启动失败?5步修复权限问题
大数据·elasticsearch·jenkins
pwj去战斗吧7 小时前
k8s+jenkins+harbor构建Devops平台
kubernetes·jenkins·devops
刘一说7 小时前
Elasticsearch安装启动常见问题全解析
大数据·elasticsearch·jenkins
小阳睡不醒1 天前
小白成长之路-jenkins使用pipline部署
运维·jenkins
Britz_Kevin1 天前
从零开始的云计算生活——第六十天,志在千里,使用Jenkins部署K8S
云计算·jenkins·生活
全糖去冰吃不了苦1 天前
ELK 集群部署实战
运维·jenkins
-KamMinG1 天前
“从零到一:使用GitLab和Jenkins实现自动化CI/CD流水线”
自动化·gitlab·jenkins
路上阡陌2 天前
ELK 部署
运维·elk·jenkins
syty20202 天前
elastic search 是如何做sum操作的
运维·jenkins