今天同时看完《Pro Continuous Delivery With Jenkins 2.0》,

这书与工作关系很大,但也是快速翻翻。

本书着重点jenkins高可用环境搭建,与github,k8s的集成。

如果是新手,baby step方式,很有亲和力。

于我,收获一个成熟的pipeline script.

node('docker_it') {

    stage('Poll') {
        checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations:
        false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'github-account',
        url: 'https://github.com/pro-continuous-delivery/hello-world-greeting.git']]])
    }
    
    stage('Build'){
        sh 'mvn clean verify -DskipITs=true';
    }
    
    stage('Static Code Analysis'){
        sh 'mvn clean verify sonar:sonar';
    }
    
    stage ('Integration Test'){
        sh 'mvn clean verify -Dsurefire.skip=true';
    }
    
    stage ('Publish to Artifactory'){
        def server = Artifactory.server 'Default Artifactory Server'
        def uploadSpec = """{
            "files": [{
                "pattern": "target/hello-0.0.1.war",
                "target": "helloworld-greeting-project/${BUILD_NUMBER}/",
                "props": "Integration-Tested=Yes;Performance-Tested=No"
            }]
        }"""
        server.upload(uploadSpec)
    }
    
    stash includes: 'target/hello-0.0.1.war,src/pt/Hello_World_Test_Plan.jmx', name: 'binary'
}
    
node('docker_pt') {
    
    stage ('Start Tomcat'){
        sh '''cd /home/jenkins/tomcat/bin
        ./startup.sh''';
    }
    
    stage ('Deploy to Testing Env'){
        unstash 'binary'
        sh 'cp target/hello-0.0.1.war /home/jenkins/tomcat/webapps/';
    }
    
    stage ('Performance Testing'){
        sh '''cd /opt/jmeter/bin/
        ./jmeter.sh -n -t /home/jenkins/workspace/helloworld-greeting-cd/src/pt/Hello_World_
        Test_Plan.jmx -l /home/jenkins/workspace/helloworld-greeting-cd/test_report.jtl''';
        step([$class: 'ArtifactArchiver', artifacts: '**/*.jtl'])
    }
    
    stage ('Promote build in Artifactory'){
        withCredentials([usernameColonPassword(credentialsId: 'artifactory-account', variable:
        'credentials')]) {
            sh 'curl -u${credentials} -X PUT "http://172.17.8.108:8081/artifactory/api/storage/
            helloworld-greeting-project/${BUILD_NUMBER}/hello-0.0.1.war?properties=Performance-
            Tested=Yes"';
        }
    }
}

 

转载于:https://www.cnblogs.com/aguncn/p/11230277.html

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐