jenkins pipeline

pipeline {
agent any
tools {
maven ‘maven3.6.2’
jdk ‘jdk1.8’
}
stages {
stage (‘Initialize’) {
steps {
sh ‘’’
echo “PATH = ${PATH}”
echo “M2_HOME = ${M2_HOME}”
‘’’
}
}

    stage ('Checkout') {
        steps {
            echo 'Get Codes from git'
            //checkout([$class: 'GitSCM', branches: [[name: '*/dev']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '9f8f3955-a3fb-46fe-a111-96e12b4da820', url: 'ssh://git@reviews.amat.com:2222/diffusion/ZHDW/zhonghuandwcim.git']]])
            git branch: 'dev', credentialsId: '9f8f3955-a3fb-46fe-a111-96e12b4da820', url: 'ssh://git@reviews.amat.com:2222/diffusion/ZHDW/zhonghuandwcim.git'            
            
        }
    }
    
    stage ('Build') {
        steps {
            echo 'Building'
            sh '"${M2_HOME}/bin/mvn" -Dmaven.repo.local=/home/aj/.m2/repository -f MES_Backend/WebService/pom.xml -Dmaven.test.failure.ignore clean package'
            }
    }
    
    stage ('Generate') {
        steps {
            junit '**/MES_Backend/WebService/target/surefire-reports/TEST-*.xml'
            archiveArtifacts 'MES_Backend/WebService/target/*.jar'
        }  
    }
    
    stage ('Report-JaCoCo') {
        steps {
            echo 'JaCoco'
        }
        post {
            success {
                jacoco execPattern: '**/MES_Backend/WebService/target/**.exec'
            }
        }            
    }
    
    stage ('Report-AllureReport') {
        steps {
            echo 'AllureReport'
        }
        post {
            success {
                allure includeProperties: false, jdk: 'jdk1.8', results: [[path: 'MES_Backend/WebService/target/allure-results']]
            }
        }
    }
    
    stage ('Deploy') {
        steps {
            echo 'Delpoy to Server 166'
        }
        post {
            success {
                sshPublisher(publishers: [sshPublisherDesc(configName: 'ZhonghuanServer', sshCredentials: [encryptedPassphrase: '{AQAAABAAAAAQTpX80BT0G3jsKLmcfJLI8oGHoJ4/dybS3VJyebzoEEM=}', key: '', keyPath: '', username: 'root'], transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '''#!/bin/bash
                    SERVER_NAME=zhonghuanmes
                    JAR_WORK_PATH=/usr/local/zhonghuan/backend/target
                    JAR_NAME=zhonghuanmes-0.0.1-SNAPSHOT
                    
                    echo "Search ProgressID-->$SERVER_NAME"
                    PID=`ps -ef | grep "$SERVER_NAME" | grep -v grep | awk \'{print $2}\'`
                    echo "Get ProgressID: $PID"
                    echo "End Progress"
                    
                    for id in $PID
                    do
                         kill -9 $id
                         echo "killed $id"
                    done
                    echo "End Progress finished"
                    
                    cd $JAR_WORK_PATH
                    
                    #source /etc/profile
                    #nohup java -jar $JAR_NAME.jar > nohup.out & sleep 1
                    BUILD_ID=dontKillMe nohup java -jar  $JAR_NAME.jar & sleep 1''', execTimeout: 120000, flatten: true, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'target/', remoteDirectorySDF: false, removePrefix: 'MES_Backend/WebService/target/', sourceFiles: 'MES_Backend/WebService/target/zhonghuanmes-0.0.1-SNAPSHOT.jar', usePty: true)], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
            }
        }
    }
}

}

jenkins pipelinejenkins pipeline AJ校长 发布了23 篇原创文章 · 获赞 0 · 访问量 1万+ 私信 关注
上一篇:FCOS: Fully Convolutional One-Stage Object Detection


下一篇:jenkins实现并发任务执行