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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值