jenkins pipeline下载代码到指定workspace

导语:jenkins pipeline下载代码到指定workspace下。因为项目有算法和算法权重,是2个gitlab项目管理,但是算法代码和权重代码分支需要对应,因此想使用一个job进行构建。下载权重到当前workspace,下载算法到自定义workspace,并且需要把权重覆盖到算法里。

主要通过这一条。设置超时和自定义workspace

extensions: [[$class: 'CloneOption', noTags: false, reference: '', shallow: false, timeout: 60000],[$class: 'RelativeTargetDirectory', relativeTargetDir: '/data/jenkins/workspace/lung-base']],
#!groovy

pipeline {
    agent {
        label "172.16.40.245"
    }

    //定义构建参数
    parameters {
        choice(name: '发布环境', choices: ['DxAI-Prod'], description: '请选择需要发布的环境')
        gitParameter name: 'BRANCH', type: 'PT_BRANCH_TAG', branchFilter: '(.*\\b)', listSize: '10', defaultValue: '20220531_sp2', selectedValue: 'TOP', sortMode: 'DESCENDING'
        imageTag(name: 'DOCKER_IMAGE', description: '',
            image: 'base/lung', filter: '.*', defaultTag: 'ge930',
             registry: 'http://harbor.deepwise.com', credentialId: '18060a85-ebcf-4aa4-bca7-b267c07497f3', tagOrder: 'NATURAL') 
    }

    //定义变量
    environment {
        // Unzip_Path="/data1/TestPackage/lung/cta/"
        Tag = "`date '+%Y-%m-%d-%H'-${BUILD_NUMBER}`"
        // 项目名称
        // PROJECT = 'DxAI'
        // 工程名称
        // APP_NAME = "dxPython"
        // 发布环境
        // DEPLOY_ENV = "${params.发布环境}"
        // 仓库地址
        // GIT_REPO = "${params.GIT_REPO}"
        // 仓库分支
        // BRANCH = "${params.BRANCH}"
        // 备份路径
        // BAK_PATH = "/mnt/backup/"
        // 模块路径
        // APP_PATH = "/data1/docker_data/wwwroot/research"
        //默认邮件接收人
        // DEFAULT_EMAIL = 'dengli@deepwise.com'
        //负责邮件接收人
        // OWNER_EMAIL = ''
        //PL邮件接收人
        // PL_EMAIL = ' '
    }

    //来源全局设置配置的变量
//     tools {
// //        jdk 'java-8'
//         maven 'maven-3.6.0'
//     }

    options {
        timestamps()
        //保持构建的最大个数
        buildDiscarder(logRotator(numToKeepStr: '10'))
    }




    //执行任务模块
    stages {
        //拉取代码模块
        stage('Checkout weight') {
            steps {
                //deleteDir()
                echo "---------------------------------------------------------------------------------"
                echo "Starting Checkout Code......"
                echo "---------------------------------------------------------------------------------"
                script {
                    echo "starting fetchCode from http://xxxx.deepwise.com/dw/xxxx.git......"
                    checkout([$class           : 'GitSCM',
                              branches         : [[name: "${BRANCH}"]],
                              doGenerateSubmoduleConfigurations: false,
                              extensions: [[$class: 'CloneOption', noTags: false, reference: '', shallow: false, timeout: 60000]],
                              userRemoteConfigs: [[credentialsId: '81f18226-d36e-4a0e-bd0e-b936843ae77b',
                                                   url          : "http://xxxx.deepwise.com/dw/xxxx.git",]]
                    ])
                }
            }
        }
        stage('Checkout lung') {
            steps {
                //mkdir lung

                //deleteDir()
                echo "---------------------------------------------------------------------------------"
                echo "Starting Checkout Code......"
                echo "---------------------------------------------------------------------------------"
                println env.WORKSPACE
			    dir("/data/jenkins/workspace/lung"){
			        sh "sleep 300"
			        sh "echo pwd"
				    sh "pwd"
			    }

                script {
                    echo "starting fetchCode from http://xxxx.deepwise.com/dw/xxxx.git......"
                    checkout([$class           : 'GitSCM',
                              branches         : [[name: "${BRANCH}"]],
                              doGenerateSubmoduleConfigurations: false,
                              extensions: [[$class: 'CloneOption', noTags: false, reference: '', shallow: false, timeout: 60000],[$class: 'RelativeTargetDirectory', relativeTargetDir: '/data/jenkins/workspace/lung-base']],
                              userRemoteConfigs: [[credentialsId: '81f18226-d36e-4a0e-bd0e-b936843ae77b',
                                                  url          : "http://xxxx.deepwise.com/dw/xxxx.git",]]
                    ])
                }
            }
        }


        //打包模块
        stage('Package') {
            steps {
                echo "---------------------------------------------------------------------------------"
                echo "Starting Gradlew package ......"
                echo "---------------------------------------------------------------------------------"
                script {
                    sh """
                        echo "package"
                       """
                }
            }
        }

        stage('Publish') {
            steps {
                echo "---------------------------------------------------------------------------------"
                echo "Starting Publish apk to Remote ......"
                echo "---------------------------------------------------------------------------------"
                // script {
                //     sshPublisher(publishers:
                //             [sshPublisherDesc(configName: "$DEPLOY_ENV",
                //                     transfers: [sshTransfer(cleanRemote: false,
                //                             excludes: '',
                //                             execCommand: 'ls /tmp/dxPython*',
                //                             execTimeout: 120000,
                //                             flatten: false,
                //                             makeEmptyDirs: false,
                //                             noDefaultExcludes: false,
                //                             patternSeparator: '[, ]+',
                //                             remoteDirectory: '/tmp',
                //                             remoteDirectorySDF: false,
                //                             removePrefix: '',
                //                             sourceFiles: 'dxPython.tgz')],
                //                     usePromotionTimestamp: false,
                //                     useWorkspaceInPromotion: false,
                //                     verbose: false)])
                // }
            }
        }

        stage('Install') {
            agent {
                label "172.16.40.245"
            }
            steps {
                echo "---------------------------------------------------------------------------------"
                echo "Starting Install Application......"
                echo "---------------------------------------------------------------------------------"
                script {
                    sh """
                        echo 123
                       """
                }
            }
        }
    }
}

贴个最后成功的图,因为异地同步,陆陆续续下载了一天左右

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爷来辣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值