导语: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
"""
}
}
}
}
}
贴个最后成功的图,因为异地同步,陆陆续续下载了一天左右