Commit 02b89017 authored by wentao.suo's avatar wentao.suo

fff

parent 2fc01b1c
...@@ -3,113 +3,114 @@ ...@@ -3,113 +3,114 @@
def call(body) { def call(body) {
ansiColor('xterm') {
def _stage = new org.qg.docker_new.StageBucket() def _stage = new org.qg.docker_new.StageBucket()
def _utils = new org.qg.docker_new.Utils() def _utils = new org.qg.docker_new.Utils()
def config = [:] def config = [:]
def timeStemp = new Date().format("yyyyMMddHHmmss") def timeStemp = new Date().format("yyyyMMddHHmmss")
def env = body.env def env = body.env
def branchName = env.BRANCH_NAME def branchName = env.BRANCH_NAME
def gitRepo = env.GIT_REPO def gitRepo = env.GIT_REPO
def namespace = env.NAMESPACE def namespace = env.NAMESPACE
def isDeploy = env.IS_DEPLOY def isDeploy = env.IS_DEPLOY
def buildNumber = env.BUILD_NUMBER def buildNumber = env.BUILD_NUMBER
def cluster = env.CLUSTER def cluster = env.CLUSTER
t = gitRepo.split("/") t = gitRepo.split("/")
def gitGroup = t[0] def gitGroup = t[0]
def systemName = t[1].toLowerCase() def systemName = t[1].toLowerCase()
def contextDir def contextDir
def imageTag def imageTag
regex = "[`,./;\\[\\]&<>?:\"()|-]+" regex = "[`,./;\\[\\]&<>?:\"()|-]+"
k8sSystemName = systemName.replaceAll("_","-") k8sSystemName = systemName.replaceAll("_","-")
safeBranchName = branchName.replaceAll(regex,"_") safeBranchName = branchName.replaceAll(regex,"_")
body.resolveStrategy = Closure.DELEGATE_FIRST body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config body.delegate = config
body() body()
node { node {
try { try {
echo config.buildType echo config.buildType
stage('prepare') { stage('prepare') {
_utils.beautyEcho("Prepare", "stage") _utils.beautyEcho("Prepare", "stage")
contextDir = _stage.contextMkdir("${systemName}-${timeStemp}") contextDir = _stage.contextMkdir("${systemName}-${timeStemp}")
_stage.before_prepare() _stage.before_prepare()
} }
pacegeDockerInfo = _stage.getDocketPackageImage(config.buildType) pacegeDockerInfo = _stage.getDocketPackageImage(config.buildType)
withDockerServer([uri: "tcp://192.168.4.96:2375/"]) { withDockerServer([uri: "tcp://192.168.4.96:2375/"]) {
stage('checkout & build') { stage('checkout & build') {
_utils.beautyEcho("checkout & build", "stage") _utils.beautyEcho("checkout & build", "stage")
docker.image(pacegeDockerInfo["images"]).inside(pacegeDockerInfo["args"]){ docker.image(pacegeDockerInfo["images"]).inside(pacegeDockerInfo["args"]){
project_attr = _stage.project_attr(systemName) project_attr = _stage.project_attr(systemName)
gitPath = project_attr["gitPath"] gitPath = project_attr["gitPath"]
/*checkout code*/ /*checkout code*/
_utils.beautyEcho("checkout", "stage") _utils.beautyEcho("checkout", "stage")
_stage.checkout(git_path, branchName) _stage.checkout(git_path, branchName)
/*prepare config*/ /*prepare config*/
_utils.beautyEcho("prepare config", "stage") _utils.beautyEcho("prepare config", "stage")
_stage.prepare_config(systemName, contextDir) _stage.prepare_config(systemName, contextDir)
/*build*/ /*build*/
_utils.beautyEcho("build", "stage") _utils.beautyEcho("build", "stage")
buildCmd = project_attr["buildCmd"] buildCmd = project_attr["buildCmd"]
sh "${buildCmd}" sh "${buildCmd}"
/*copy files*/ /*copy files*/
_stage.copy_files(config.buildType,project_attr["jarFilePath"],contextDir) _stage.copy_files(config.buildType,project_attr["jarFilePath"],contextDir)
}
} }
}
stage('make docker image') { stage('make docker image') {
imageTag = "192.168.4.36/${harborGroup}/${k8sSystemName}:${safeBranchName}-${timeStemp}" imageTag = "192.168.4.36/${harborGroup}/${k8sSystemName}:${safeBranchName}-${timeStemp}"
withDockerRegistry([credentialsId: 'harbor-qajenkins', url: "http://192.168.4.36"]) { withDockerRegistry([credentialsId: 'harbor-qajenkins', url: "http://192.168.4.36"]) {
def build_schema = "BUILD_TIME: ${timeStemp} ,BUILD_NUMBER: ${buildNumber},SYSTEM_NAME: ${systemName},BRANCH_NAME: ${branchName}, CLUSTER: ${cluster}" def build_schema = "BUILD_TIME: ${timeStemp} ,BUILD_NUMBER: ${buildNumber},SYSTEM_NAME: ${systemName},BRANCH_NAME: ${branchName}, CLUSTER: ${cluster}"
def image = docker.build(imageTag, "--build-arg BUILD_SHCEMA=build_schema ${contextDir}") def image = docker.build(imageTag, "--build-arg BUILD_SHCEMA=build_schema ${contextDir}")
image.push() image.push()
if (branchName == "master" || branchName == "master--master") { if (branchName == "master" || branchName == "master--master") {
image.push('latest') image.push('latest')
} }
} }
} }
} }
}catch (err) { }catch (err) {
try{ try{
currentBuild.result = 'FAILED' currentBuild.result = 'FAILED'
_utils.beautyEcho(err, "fail") _utils.beautyEcho(err, "fail")
}catch (err1) { }catch (err1) {
_utils.beautyEcho(err, "fail") _utils.beautyEcho(err, "fail")
} }
}finally{ }finally{
sh "rm -rf ${contextDir}" sh "rm -rf ${contextDir}"
_stage.clean_images(imageTag) _stage.clean_images(imageTag)
} }
} }
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment