jenkins pipeline maven 使用

pipeline {

  /*
   * Run everything on an existing agent configured with a label ‘docker‘.
   * This agent will need docker, git and a jdk installed at a minimum.
   */
  agent {
    node {
      label ‘docker‘
    }
  }

  // using the Timestamper plugin we can add timestamps to the console log
  options {
    timestamps()
  }

  environment {
    //Use Pipeline Utility Steps plugin to read information from pom.xml into env variables
    IMAGE = readMavenPom().getArtifactId()
    VERSION = readMavenPom().getVersion()
  }

  stages {
    stage(‘Build‘) {
      agent {
        docker {
          /*
           * Reuse the workspace on the agent defined at top-level of Pipeline but run inside a container.
           * In this case we are running a container with maven so we don‘t have to install specific versions
           * of maven directly on the agent
           */
          reuseNode true
          image ‘maven:3.5.0-jdk-8‘
        }
      }
      steps {
        // using the Pipeline Maven plugin we can set maven configuration settings, publish test results, and annotate the Jenkins console
        withMaven(options: [findbugsPublisher(), junitPublisher(ignoreAttachments: false)]) {
          sh ‘mvn clean findbugs:findbugs package‘
        }
      }
      post {
        success {
          // we only worry about archiving the jar file if the build steps are successful
          archiveArtifacts(artifacts: ‘**/target/*.jar‘, allowEmptyArchive: true)
        }
      }
    }

    stage(‘Quality Analysis‘) {
      parallel {
        // run Sonar Scan and Integration tests in parallel. This syntax requires Declarative Pipeline 1.2 or higher
        stage (‘Integration Test‘) {
          agent any  //run this stage on any available agent
          steps {
            echo ‘Run integration tests here...‘
          }
        }
        stage(‘Sonar Scan‘) {
          agent {
            docker {
              // we can use the same image and workspace as we did previously
              reuseNode true
              image ‘maven:3.5.0-jdk-8‘
            }
          }
          environment {
            //use ‘sonar‘ credentials scoped only to this stage
            SONAR = credentials(‘sonar‘)
          }
          steps {
            sh ‘mvn sonar:sonar -Dsonar.login=$SONAR_PSW‘
          }
        }
      }
    }

    stage(‘Build and Publish Image‘) {
      when {
        branch ‘master‘  //only run these steps on the master branch
      }
      steps {
        /*
         * Multiline strings can be used for larger scripts. It is also possible to put scripts in your shared library
         * and load them with ‘libaryResource‘
         */
        sh """
          docker build -t ${IMAGE} .
          docker tag ${IMAGE} ${IMAGE}:${VERSION}
          docker push ${IMAGE}:${VERSION}
        """
      }
    }
  }

  post {
    failure {
      // notify users when the Pipeline fails
      mail to: ‘[email protected]‘,
          subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
          body: "Something is wrong with ${env.BUILD_URL}"
    }
  }
}

原文地址:https://www.cnblogs.com/flyhgx/p/8321356.html

时间: 2024-10-06 06:40:31

jenkins pipeline maven 使用的相关文章

jfrog artifactory jenkins pipeline 集成

1. 预备环境 artifactory ( 开源版本 ) maven jenkins jenkins artifactory plugin (在插件管理安装即可) 2. 配置artifactory a. maven local 仓库 b. jenkins 配置(添加 artifactory 账户信息) 3.  jenkins  pipeline 配置(实例使用github 实例) jenkinsfile 内容如下: node("docker-64") { def server = Ar

Jenkins pipeline:pipeline 使用之语法详解

一.引言 Jenkins 2.0的到来,pipline进入了视野,jenkins2.0的核心特性. 也是最适合持续交付的feature. 简单的来说,就是把Jenkins1.0版本中,Project中的相关配置信息,如SVN/Git的配置,Parameter的配置等都变成Code,即Pipeline as Code. 随着pipeline交付流水线在团队中的推广,使用pipeline脚本的job也迅速增加. 优势: 通过写代码的形式配置Project,且Jenkins中内置了常用的steps.

基于Jenkins Pipeline自动化部署

最近在公司推行Docker Swarm集群的过程中,需要用到Jenkins来做自动化部署,Jenkins实现自动化部署有很多种方案,可以直接在jenkins页面写Job,把一些操作和脚本都通过页面设置,也可以在每个项目中直接写Pipeline脚本,但像我那么优秀,那么追求极致的程序员来说,这些方案都打动不了我那颗骚动的心,下面我会跟你们讲讲我是如何通过Pipeline脚本实现自动化部署方案的,并且实现多分支构建,还实现了所有项目共享一个Pipeline脚本. 使用Jenkins前的一些设置 为了

Jenkins通过maven构建编译JAVA项目

Jenkins 通过maven 构建编译 JAVA 项目环境 官网下载合适Jenkins版本包: jenkins http://mirrors.jenkins.io/war-stable/  Jdk curl -L -O http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.tar.gz  JDK SE http://120.52.72.24/download.oracle.com/c3pr90ntc0td

CentOS6.8 部署Tomcat+jenkins+git+maven 持续集成

CentOS6.8 部署Tomcat+jenkins+git+maven 持续集成 一.环境介绍: 1.操作系统:CentOS 6.8  IP:192.168.1.100 2.JDK版本:jdk1.8.0_101 3.Tomcat版本:tomcat-9.0.0.M21 4.jenkins版本: Jenkins ver. 2.46.3 5.git版本:git version 2.9.4 6.maven版本:3.5.0 二.环境部署 1.下载所需软件包 # mkdir /tmp/soft ; cd

jenkins+git+maven搭建自动化部署项目环境

简介    折腾了两个晚上,趁着今晚比较有空,把jenkins+git+maven搭建自动化部署项目环境搭建的过程记录一下,这里我把github作为git的远程仓库(https://github.com/jacky-        lulu/cxf_demo-Maven-Webapp)     系统:centos6.5 maven: Apache Maven 3.3.9 git:git version 2.0.0 1.首先安装git,看以前另外一篇博客 http://www.cnblogs.co

Jenkins + Git + Maven + tomcat集成环境搭建

折腾了好几天,终于吧Jenkins + Git + Maven + tomcat集成环境搭建起来了,最终主要实现"自动构建.部署"web应用. 1.安装环境 操作系统:Centos 6.5 JDK:1.7.x Maven:3.1.x Git: 1.7.1,自建GitLab平台 tomcat:7.x 上述宿主机器2台:192.168.1.194,192,168.1.198,其中194位Jenkins Master,198位slave. 2.第三方安装安装和环境配置 JDK.Git.Mav

Jenkins 本地Maven仓库隔离策略

一.概述 如果只使用一个Maven仓库,很容易会造成拥有相同的GroupID/ArtifactID/Version的JOB,在install时会在本地Maven仓库相互覆盖,所以我们要仓库隔离 二.隔离策略 2.1 隔离原因 开发分支JOB和主干JOB会相互覆盖. CI JOB和打包发布JOB会相互覆盖. 2.2 隔离方法 View划分保持一致,Jenkins本地Maven仓库也分成四个,即: CI 开发分支仓库:ci-dev-repo CI 主干仓库:ci-tru-repo 打包开发分支仓库:

jenkins+gitlab+maven+tomcat持续集成环境安装配置

jenkins+gitlab+maven+tomcat,该环境主要实现自动构建部署java web应用. 其工作流程是:提交代码到gitlab--jenkins触发构建任务--maven编译打包--jenkins将war包部署到tomcat. 安装JDK #安装jdk1.8 tar zxvf jdk-8u77-linux-x64.gz #设置环境变量 #vi /etc/profile export JAVA_HOME=/usr/local/jdk1.8.0_77 export JAVA_BIN=