码迷,mamicode.com
首页 > 其他好文 > 详细

jenkins pipeline maven 使用

时间:2018-01-20 18:52:35      阅读:3506      评论:0      收藏:0      [点我收藏+]

标签:als   使用   something   ase   hive   label   resource   inf   tac   

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: ‘team@example.com‘,
          subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
          body: "Something is wrong with ${env.BUILD_URL}"
    }
  }
}

jenkins pipeline maven 使用

标签:als   使用   something   ase   hive   label   resource   inf   tac   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!