Jenkins pipline

pipeline {
agent any 
options {
    durabilityHint 'PERFORMANCE_OPTIMIZED'
    timeout(time:5, unit: 'MINUTES')
    timestamps()
    skipStagesAfterUnstable()
    skipDefaultCheckout true
    buildDiscarder logRotator(artifactDaysToKeepStr: '1', artifactNumToKeepStr: '1', daysToKeepStr: '10', numToKeepStr: '5')
}
stages {
    stage('拉取代码') {
        steps {
            echo 'It is now pulling code for remote qe github...'                
            script {
                try {                                
                    checkout([$class: 'GitSCM', branches: [[name: 'LSH-E2E']],userRemoteConfigs: [[credentialsId: '36467a7d-bd04-4872-9010-00f2691d1648', url: 'git@github.com:LiveRamp/qe.git']]])
                } catch(Exception err) {
                    echo err.getMessage()
                    echo err.toString()
                    unstable 'pull code failed'
                    warnError('拉取代码失败信息回调失败') {
                        retry(2){
                            httpRequest acceptType: 'APPLICATION_JSON', consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', httpMode: 'POST', ignoreSslErrors: true, requestBody: "{\"step\":\"pull\",\"id\":\"${JOB_NAME}\",\"build_number\":\"${BUILD_NUMBER}\"}", timeout: 5, url: 'http://127.0.0.1:8088/api/v1/job_finish', validResponseCodes: '200', validResponseContent: 'ok'                                
                        }
                    }                         
                }
            }                    
        }
    }
    stage('构建') {
        options {                
            timeout(time:3, unit: 'MINUTES')                
        }
        steps {
            echo '正在构建....'
            script {
                try {
                    sh 'pwd'    
   
                } catch (Exception err) {
                    echo err.getMessage()
                    echo err.toString()
                    unstable '构建失败'
                    warnError('构建失败信息回调失败') {
                        retry(5) {
                            httpRequest acceptType: 'APPLICATION_JSON', consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', httpMode: 'POST', ignoreSslErrors: true, requestBody: "{\"step\":\"build\",\"id\":\"${JOB_NAME}\",\"build_number\":\"${BUILD_NUMBER}\"}", timeout: 5, url: 'http://127.0.0.1:8088/api/v1/job_finish', validResponseCodes: '200', validResponseContent: 'ok'
                        }
                    }
                }
            }
        }
    }
    stage('依赖性检查') {
        steps { 
            echo '正在生成依赖性检查信息...'
            script {
                try {
                    basedir = sh returnStdout: true ,script: "PWD"
                    sh 'echo ${basedir}'
                    sh 'cp -R /Users/jasqia/Desktop/credentials /Users/jasqia/.jenkins/workspace/pipline'
                    sh 'cp -f /Users/jasqia/Desktop/.dockerignore /Users/jasqia/.jenkins/workspace/pipline'
                    sh 'cp -R /Users/jasqia/Desktop/scripts /Users/jasqia/.jenkins/workspace/pipline'
                } catch(Exception err) {
                    echo err.getMessage()
                    echo err.toString()
                    unstable '依赖性检查失败'
                    warnError('依赖性检查失败信息回调失败') {
                        retry(5) {
                            httpRequest acceptType: 'APPLICATION_JSON', consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', httpMode: 'POST', ignoreSslErrors: true, requestBody: "{\"step\":\"check\",\"id\":\"${JOB_NAME}\",\"build_number\":\"${BUILD_NUMBER}\"}", timeout: 5, url: 'http://127.0.0.1:8088/api/v1/job_finish', validResponseCodes: '200', validResponseContent: 'ok'
                        }
                    }
                }
            }
        }
    }
    stage('返回依赖性检查文件') {
        steps {
            echo '正在返回依赖性检查文件给erebsu应用...'
            script {
                try {
                    echo '正在返回依赖性检查文件给erebsu应用...'
                    sh '/usr/local/bin/docker build . -t docker-image docker/e2e_lsh/Dockerfile'
                    sh '/usr/local/bin/docker container run --env AUTO_USERNAME=${AUTO_USERNAME} --env AUTO_PASSWORD=${AUTO_PASSWORD} --env PYTHON_ENV=${PYTHON_ENV} --env CLIENT_BUCKET=${CLIENT_BUCKET}
docker-image
:ttttt' } catch(Exception err) { echo err.getMessage() echo err.toString() unstable '依赖性检查文件返回给erebus失败' warnError('依赖性检查文件返回给erebus失败信息回调失败') { retry(5) { httpRequest acceptType: 'APPLICATION_JSON', consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', httpMode: 'POST', ignoreSslErrors: true, requestBody: "{\"step\":\"callback\",\"id\":\"${JOB_NAME}\",\"build_number\":\"${BUILD_NUMBER}\"}", timeout: 5, url: 'http://127.0.0.1:8088/api/v1/job_finish', validResponseCodes: '200', validResponseContent: 'ok' } } } } } } stage('完成') { steps { echo '依赖性检查完成,正在返回完成信息...' } } } post { always { cleanWs() } } }

 

posted @ 2021-06-23 14:25  巴黎爱工作  阅读(84)  评论(0编辑  收藏  举报