zoukankan      html  css  js  c++  java
  • jenkins pipeline

    jenkins pipeline 基本模式

    pipeline {
        agent any
    
        //任务集合,一个大的任务
        stages {
            stage('代码获取') {
                steps {
                    echo "get code is ok"
                }
            }
            stage('代码质检') {
                steps {
                    echo "get code is ok"
                }
            }
            stage('代码构建') {
                steps {
                    echo "build is ok"
                }
            }
            stage('代码部署') {
                steps {
                    echo "deploy is ok"
                }
            }
        }
    }
    pipeline {
        agent any
    
        //任务集合,一个大的任务
        stages {
            stage('代码获取') {
            steps {
            checkout([$class: 'GitSCM', branches: [[name: '${git_version}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '0f180207-47af-4820-a956-a20fdd1f445f', url: 'git@gitlab.abc.com:/api.git']]])
                }
            }
            stage('代码质检') {
                steps {
                    withSonarQubeEnv('SonarQube') {
                        sh '/usr/local/sonar-scanner/bin/sonar-scanner -Dsonar.projectKey=stg-api -Dsonar.projectName=${JOB_NAME} -Dsonar.sources=. -Dsonar.java.binaries=target/'
                    }
                        script {
                           timeout(3) {
                               sleep(10)
                               def qg = waitForQualityGate()
                               if (qg.status != 'OK') {
                                   error "未通过SonarQube的代码检查,请及时修改! failure: ${qg.status}"
                               }
                           }
                       }
                }
            }
            stage('代码构建') {
                steps {
                    sh '/bin/mvn clean install'
                }
            }
            stage('代码部署') {
                steps {
                    sh '/usr/local/shell/stg-api.sh'
                }
            }
        }
        post {
            failure {
                dingTalk accessToken: 'd631ae76dabd6fabba81b1fe4a7f3d2fe3a8da8636ba72554348ef71e1982a2a', imageUrl: 'http://jenkins.abc.com/dingding_fail.png', jenkinsUrl: 'http://jenkins.abc.com:8080/', message: '代码部署失败', notifyPeople: 'phone' 
            }
            success {
                dingTalk accessToken: 'd631ae76dabd6fabba81b1fe4a7f3d2fe3a8da8636ba72554348ef71e1982a2a', imageUrl: 'http://jenkins.abc.com/dingding_OK.png', jenkinsUrl: 'http://jenkins.abc.com:8080/', message: '代码部署成功', notifyPeople: 'phone'
            }
    
        }
    }
  • 相关阅读:
    商品表(spu)、规格表(sku)设计
    Links
    About
    AFO
    口胡题
    NOIP2014 飞扬的小鸟
    CSP2019 Emiya 家今天的饭
    CSP2019 括号树
    CSP-J2019 加工零件
    CSP-J2019 纪念品
  • 原文地址:https://www.cnblogs.com/faberbeta/p/jenkins003.html
Copyright © 2011-2022 走看看