jenkins pipeline 使用maven docker

安装jenkins以及插件maven完成后,如果没有安装插件Pipeline Maven Integration,就会包一下错误
maven

现在安装Pipeline Maven Integration插件
插件
安装完成后重启jenkins就可以了

pipeline

node{
    stage('get clone'){
        //check CODE
        echo 'Checkout==========》》》'
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://source.enncloud.cn/qinzhao/spring-boot-demo.git']]])
    }

    //定义mvn环境
    def mvnHome = tool 'maven3.5.3'
    env.PATH = "${mvnHome}/bin:${env.PATH}"

    stage('mvn test'){
        //mvn 测试
        sh "mvn test"
    }

    stage('mvn build'){
        //mvn构建
        sh "mvn clean install -Dmaven.test.skip=true"
    }

    stage('deploy'){
        //执行部署脚本
        echo "deploy ......" 
    }
}

1111

在宿主机上安装docker这里牛不多说了

yum install docker -y 
systemctl start docker

pipeline docker maven 脚本

node{
    stage('get clone'){
        //check CODE
        echo 'Checkout==========》》》'
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://source.enncloud.cn/qinzhao/spring-boot-demo.git']]])
    }

    //定义mvn环境
    def mvnHome = tool 'maven3.5.3'
    env.PATH = "${mvnHome}/bin:${env.PATH}"

    stage('mvn test'){
        //mvn 测试
        sh "mvn test"
    }

    stage('mvn build'){
        //mvn构建
        sh "mvn clean install -Dmaven.test.skip=true"
    }

    stage('deploy'){
        //执行部署脚本
        sh "ls -l target"
        echo "deploy ......" 
    }
    def dockerfile = 'Dockerfile'
    def customImage = docker.build("10.39.47.22/qinzhao/demo:v1.0", "-f ${dockerfile} .")
    customImage.push()

}

执行结果
ku

查看镜像
demo
参考:
https://blog.csdn.net/boonya/article/details/77941975

你可能感兴趣的:(java,java,后端)