jenkins持续集成3

1.安装Pipeline插件,并初识

//pipeline script脚本
node {
   def mvnHome
   stage('Preparation') { // for display purposes
      // Get some code from a GitHub repository
      //guan fang官方
      //git 'https://github.com/jglick/simple-maven-project-with-tests.git'
      git 'https://github.com/nbbull/demoProject.git'
      // Get the Maven tool.
      // ** NOTE: This 'M3' Maven tool must be configured
      // **       in the global configuration.           
      mvnHome = tool 'M3'
   }
   stage('Build') {
      // Run the maven build
      if (isUnix()) {
         sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package"
      } else {
         bat(/"${mvnHome}\bin\mvn" -Dmaven.test.failure.ignore clean package/)
      }
   }
   stage('Results') {
      junit '**/target/surefire-reports/TEST-*.xml'
      archive 'target/*.jar'
   }
}
#声明式
#!groovy

pipeline {
    environment{
            mvnHome = tool 'M3'
        }
    agent any
    stages {
        stage ('Preparation'){
            steps{
                git 'https://github.com/nbbull/demoProject.git'
                
            }
        }
        stage ('Build'){
            steps{
                script{
                if (isUnix()) {
                    sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package"
                } else {
                    bat(/"${mvnHome}\bin\mvn" -Dmaven.test.failure.ignore clean package/)
                }
                }
            }
            
        }
        stage ('Results'){
            steps{
                junit '**/target/surefire-reports/TEST-*.xml'
                archive 'target/*.jar'
            }
        }
   }    
}

FAQ:

1.声明式脚本包含方法的要放在script里面

2.环境变量要方法哦pipeline里面,不能和pipeline平行

posted on 2018-10-14 11:38  singleSpace  阅读(391)  评论(0)    收藏  举报