def pipeId = 1130561944231279390
def pipeLogId
def isTagOrBranch
def tagOrBranch
def imageId
def addPipelineLog() {
def isUserTriggered = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) != null
def isGitLabWebHookTriggered = currentBuild.rawBuild.getCause(com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause) != null
def isTimerTriggered = currentBuild.rawBuild.getCause(hudson.triggers.TimerTrigger$TimerTriggerCause) != null
def isUpstreamTriggered = currentBuild.rawBuild.getCause(hudson.model.Cause.UpstreamCause) != null
println "trigger type:"+currentBuild.rawBuild.getCauses().dump()
println "params.logId: "+params.logId
println "params.projectVersionConfigId: "+params.projectVersionConfigId
println "params.publishLogId: "+params.publishLogId
println "params.preExecuteEndPipeStageId: "+params.preExecuteEndPipeStageId
def reqPipeLogId = params.logId
def command = $/curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZW1zY210In0.7Kno6QoIFmT8nQv-C2edlP514ekqy9pPNID_Vf__DPc' -d '{"pipeId":1130561944231279390,"pipeLogId":"$reqPipeLogId","isUserTriggered":$isUserTriggered,"isGitLabWebHookTriggered":$isGitLabWebHookTriggered,"isTimerTriggered":$isTimerTriggered,"isUpstreamTriggered":$isUpstreamTriggered}' "http://10.145.196.76:12000/pipeline/pipelines/pipelineLog" /$
res = sh(returnStdout: true, script: command).trim()
println "add pipeline log result:\n" + res
return parseJsonText(res).body.content
}
def getStageLog(log) {
def stageLog = log.substring(log.lastIndexOf("[Pipeline] stage"))
echo "log size:" + stageLog.length()
return URLEncoder.encode(stageLog, "UTF-8")
}
def toUpdatePipelineLogCurlSh(result, duration, log, pipeLogId, pipeStageId) {
def tmpDir = 'deploy_tmp'
def tmpFile = 'updatePipelineLog_params_tmp'
def data = '{"flag":"'+result+'","duration":"'+duration+'","message":"'+log+'","pipeLogId":"'+pipeLogId+'","pipeStageId":"'+pipeStageId+'","preExecuteEndPipeStageId":"'+preExecuteEndPipeStageId+'"}';
writeToFile(env.WORKSPACE, tmpDir, tmpFile, data)
def tmpFilePath = tmpDir + '/' + tmpFile
def curl = 'curl -X PUT --header \'Content-Type: application/json\' --header \'Accept: application/json\' --header \'token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZW1zY210In0.7Kno6QoIFmT8nQv-C2edlP514ekqy9pPNID_Vf__DPc\' --data-binary "@'+ tmpFilePath +'" "http://10.145.196.76:12000/pipeline/pipelines/pipelineStageLog" '
return curl
}
def toEndPipelineLogCurlSh(result, pipeLogId, projectVersionConfigId, publishLogId) {
def curl = 'curl -X GET --header \'token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZW1zY210In0.7Kno6QoIFmT8nQv-C2edlP514ekqy9pPNID_Vf__DPc\' "http://10.145.196.76:12000/pipeline/pipelines/pipeLineLog/'+pipeLogId+'?flag='+result+'&projectVersionConfigId='+projectVersionConfigId+'&publishLogId='+publishLogId+'" '
return curl
}
//预执行结束阶段校验
def preExecuteEndPipelineStageCheck(pipeStageId) {
def pipeStageIdStr = '' + pipeStageId
def isEndPoint = (params.preExecuteEndPipeStageId != null && pipeStageIdStr == params.preExecuteEndPipeStageId)
if (isEndPoint) {
println "this stage is pre-execute end stage, pre-execute finished "
error "preExecuteFinished"
}
}
//若异常是预执行结束,将result置为SUCCESS
def setPreExecuteResult(result, msg) {
if (msg == 'preExecuteFinished') {
result = 'SUCCESS'
println "this exception message is pre-execute finished , set result to SUCCESS "
println "本阶段是预执行结束阶段,预执行完成"
cleanWs()
println "clean workspace"
}
return result
}
//sonar check analysis
def toSonarCheckCurlSh(appId, appKey) {
def curl = 'curl -X POST --header \'token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZW1zY210In0.7Kno6QoIFmT8nQv-C2edlP514ekqy9pPNID_Vf__DPc\' -d \'appId='+appId+'&appKey='+appKey+'\' "http://10.145.196.76:12000/quality/analysis" '
return curl
}
def analysisSonarCheck(appId, appKey) {
def data = '?appId='+appId+'&appKey='+appKey
def url = 'http://10.145.196.76:12000/quality/analysis'+data
println "request " + url + " to analysis sonar check result \nparams: " + data
return paasPost(url, null)
}
def getSonarAppProfile(appId) {
/*
// GET
def get = new URL("http://10.145.196.76:12000/quality/app/profile/"+appId).openConnection();
get.setRequestProperty("token","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZW1zY210In0.7Kno6QoIFmT8nQv-C2edlP514ekqy9pPNID_Vf__DPc")
def getRC = get.getResponseCode();
def res;
if(getRC.equals(200)) {
res=get.getInputStream().getText()
println(res);
} else {
error "Sonar Check Stage - getSonarAppProfile(" + appId + ") get sonar app profile error :" + getRC
}
return parseJsonText(res).body.content
*/
def url = 'http://10.145.196.76:12000/quality/app/profile/'+appId
println "request " + url + " to get sonar app profile"
return paasGet(url)
}
def toApproveCurlSh(pipeId, pipeLogId, pipeStageId, buildId, jobName) {
def curl = 'curl -X POST --header \'Content-Type: application/json\' --header \'Accept: application/json\' --header \'token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZW1zY210In0.7Kno6QoIFmT8nQv-C2edlP514ekqy9pPNID_Vf__DPc\' -d \'{"pipeId":"'+pipeId+'","pipeLogId":"'+pipeLogId+'","pipeStageId":"'+pipeStageId+'","inputId":"'+pipeStageId+'","buildId":"'+buildId+'","jobName":"'+jobName+'"}\' "http://10.145.196.76:12000/pipeline/pipelines/addPersonalTask" '
return curl
}
//sync harbor image by our api
def syncPaasImage(imageId, targetCeEnv, pipeLogId, pipeStageId) {
def url = 'http://10.145.196.76:12000/pipeline/image/sync'
def data = '{"imageId":"'+imageId+'","targetCeEnv":"'+targetCeEnv+'","pipeLogId":"'+pipeLogId+'","pipeStageId":"'+pipeStageId+'"}'
println "request " + url + " to sync harbor image by pipeline's api\nparams: " + data
return paasPost(url, data)
}
//sync harbor image by ce-api directly
def syncPaasImage(url, sourceAddress, destAddress, codePackagePath, imageName, pipeLogId) {
if (imageName == null || imageName == '' || imageName == 'null') {
//适用于构建镜像阶段(选择镜像阶段不需要,yaml中已有镜像名)
imageName = getImageName(codePackagePath, pipeLogId)
}
sourceAddress = sourceAddress+':'+imageName
destAddress = destAddress+':'+imageName
def data = '{"pullpoint":"'+sourceAddress+'","pushpoint":"'+destAddress+'"}'
println "request " + url + " to sync harbor image by ce-api directly\nparams: " + data
return paasPost(url, data)
}
//record sync-image info
def recordSyncImageInfo(imageId, ceEnvKey, pipeLogId, pipeStageId) {
def url = 'http://10.145.196.76:12000/pipeline/image/syncImage'
def data = '{"imageId":"'+imageId+'", "imageCeEnv":"'+ceEnvKey+'",' +
'"pipeStageId":"'+pipeStageId+'", "pipeLogId":"'+pipeLogId+'"}'
println "request " + url + " to save sync-image info\nparams: " + data
return paasPost(url, data)
}
//build harbor image
def buildPaasImage(ceRemoteAddress, imgNamespaceName, repoName,
tagName, codeFilePath, hasAdditionalFile, curlUploadFilePara,
dockerFileType, dockerfilePath, dockerFileContent) {
//upload files
uploadImageFiles(codeFilePath, hasAdditionalFile, curlUploadFilePara,
ceRemoteAddress, imgNamespaceName, repoName, tagName);
//dockerfile
dockerfile = getDockerfileContent(dockerFileType, dockerfilePath, dockerFileContent)
//build image
buildPaasImage(dockerfile,
ceRemoteAddress, imgNamespaceName, repoName, tagName);
//wait image build finished
waitImageBuildFinished(ceRemoteAddress, imgNamespaceName, repoName, tagName);
}
//record image info
def recordImageInfo(ceEnvKey, imgNamespaceName, repoName, tagName,
isTagOrBranch, tagOrBranch, pipeLogId, pipeStageId) {
def url = 'http://10.145.196.76:12000/pipeline/image'
def data = '{"imageCeEnv":"'+ceEnvKey+'", "imageNamespace":"'+imgNamespaceName+'", "imageRepo":"'+repoName+'", "imageName":"'+tagName+'",' +
'"sourceCodeType":"'+isTagOrBranch+'", "sourceCode":"'+tagOrBranch+'",' +
'"appId":"123", "baseId":"1107175323881272818", "pipeId":"1130561944231279390", "pipeStageId":"'+pipeStageId+'",' +
'"pipeLogId":"'+pipeLogId+'"}'
println "request " + url + " to save image info\nparams: " + data
return paasPost(url, data)
}
def uploadImageFiles(codeFilePath, hasAdditionalFile, curlUploadFilePara,
ceRemoteAddress, imgNamespaceName, repoName, tagName) {
def otherFilePara = ""
if (hasAdditionalFile) {
otherFilePara = curlUploadFilePara
}
def uploadCommand = '''
#上传构建镜像所需文件
curl -F "files=@'''+codeFilePath+'''" '''+otherFilePara+''' --header "token:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZW1zY210In0.7Kno6QoIFmT8nQv-C2edlP514ekqy9pPNID_Vf__DPc" "'''+ceRemoteAddress+'''/zuul/ceimage/uploadfiles?namespace-name='''+imgNamespaceName+'''&repo-name='''+repoName+'''&tag-name='''+tagName+'''&username=temscmt"
'''
def uploadRes = sh(returnStdout: true, script: uploadCommand).trim()
println "upload image related files to paas container result:\n " + uploadRes
handleException(uploadRes, 'upload image related files to paas container')
}
def getDockerfileContent(dockerFileType, dockerfilePath, dockerFileContent) {
def tmpDir = 'deploy_tmp'
//dockerfile内容输出到文件
if (dockerFileType == 'INPUT') {
def tmpFile = 'Dockerfile_devops_tmp'
println "dockerfile content is by user input online, so need to write to a tmp file"
writeToFile(env.WORKSPACE, tmpDir, tmpFile, dockerFileContent)
dockerfilePath = tmpDir + '/' + tmpFile
}
dockerfile = readFile encoding: 'UTF-8', file: dockerfilePath
dockerfile = dockerfile.replaceAll("\n", "\\\\n")
return dockerfile
}
def writeToFile(currentPath, relativeDirPath, filename, content) {
println "write to file " + currentPath + " " + relativeDirPath + " " +filename
writeFile encoding: 'UTF-8', file: relativeDirPath+'/'+filename, text: content
println "write to file finish"
}
def buildPaasImage(dockerfile,
ceRemoteAddress, imgNamespaceName, repoName, tagName) {
def baseImageName='centos-jdk8'
def baseImageTag='latest'
def url = ceRemoteAddress + '/ceimage/build'
def data = '{"baseImageName": "'+baseImageName+'","baseImageTag": "'+baseImageTag+'", "dockerfile": "'+dockerfile+'", "namespaceName": "'+imgNamespaceName+'", "repoName": "'+repoName+'", "tag": "'+tagName+'", "username":"temscmt"}'
println "request " + url + " to build image\nparams: " + data
paasPost(url, data)
/*
def buildCommand = '''
#构建镜像
curl -X POST --header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header "token:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZW1zY210In0.7Kno6QoIFmT8nQv-C2edlP514ekqy9pPNID_Vf__DPc" \
-d '{"baseImageName": "'''+baseImageName+'''","baseImageTag": "'''+baseImageTag+'''", "dockerfile": "'''+dockerfile+'''", "namespaceName": "'''+imgNamespaceName+'''", "repoName": "'''+repoName+'''", "tag": "'''+tagName+'''", "username":"temscmt"}' \
"'''+ceRemoteAddress+'''/ceimage/build"
'''
def buildRes = sh(returnStdout: true, script: buildCommand).trim()
handleException(buildRes, 'build image to paas container error')
*/
}
def waitImageBuildFinished(ceRemoteAddress, imgNamespaceName, repoName, tagName) {
timeout(10) {
waitUntil {
def res = getCeImageBuildDetail(ceRemoteAddress, imgNamespaceName, repoName, tagName)
if (res == null) {
println " image build detail body null 镜像还未找到... "
return false
} else if (res.status == '1') {
println " image build detail status 1 镜像构建中 ... "
return false
} else if (res.status == '2') {
println " image build detail status 2 镜像构建成功 ... "
return true
} else if (res.status == '3') {
println " image build detail status 3 镜像构建失败 ... "
error "镜像构建失败"
} else {
println " image build detail status other ... " + res.status
return false
}
}
}
}
def getCeImageBuildDetail(ceRemoteAddress, imgNamespaceName, repoName, tagName) {
def url = ceRemoteAddress + '/ceimage/buildrecords/namespaces/' + imgNamespaceName + '/repos/' + repoName + '/tags/' + tagName
println "request " + url + " to get image build detail"
return paasGet(url)
}
//select harbor image
def selectPaasImage(ceRemoteAddress, imgNamespaceName, repoName, tagName) {
def res = getCeImageBuildDetail(ceRemoteAddress, imgNamespaceName, repoName, tagName)
if (res != null && res.status == '2') {
println " 镜像存在"
} else {
println " image status other ... " + res.status
error "镜像状态异常"
}
}
//ansible deploy
def ansibleDeploy() {
def url = 'http://10.145.196.76:12000/pipeline/pipelines/get/stage/config?pipeId=1130561944231279390'
println "request " + url + " to get ansible inventory and playbook"
def res = paasGet(url)
def inventory = res.inventory
//println "res.inventory:\n" + inventory
def playbook = res.playbook
println "res.playbook:\n" + playbook
def tmpDir = 'deploy_tmp';
println "inventory content is by user input online, so need to write to a tmp file"
writeToFile(env.WORKSPACE, tmpDir, 'inventory_tmp', inventory)
println "playbook content is by user input online, so need to write to a tmp file"
writeToFile(env.WORKSPACE, tmpDir, 'playbook_tmp.yml', playbook)
}
//deploy paas app
def deployPaasApp(pipeStageId, codePackagePath, pipeLogId) {
def codeFileNoExt = ''
if (codePackagePath != null && codePackagePath != '' && codePackagePath != 'null') {
//适用于构建镜像阶段(选择镜像阶段不需要,yaml中已有镜像名)
codeFileNoExt = getCodeFileNameNoExt(codePackagePath)
}
def url = 'http://10.145.196.76:12000/pipeline/pipelines/paasdeploy'
def data = '{"pipeId":"1130561944231279390","pipeStageId":"'+pipeStageId+'","parameters":{"codeFileNoExt":"'+codeFileNoExt+'","buildId":"'+env.BUILD_ID+'","pipeLogId":"'+pipeLogId+'"}}'
println "request " + url + " to deploy paas app\nparams: " + data
return paasPost(url, data)
/*
def command = '''
#容器应用发布
curl -X POST --header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header "token:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZW1zY210In0.7Kno6QoIFmT8nQv-C2edlP514ekqy9pPNID_Vf__DPc" \
-d '{"pipeId": "1130561944231279390","pipeStageId": "'''+pipeStageId+'''", "parameters": {"codeFileNoExt":"'''+codeFileNoExt+'''", "buildId": "'''+env.BUILD_ID+'''", "pipeLogId": "'''+pipeLogId+'''"}}' \
"http://10.145.196.76:12000/pipeline/pipelines/paasdeploy"
'''
def res = sh(returnStdout: true, script: command).trim()
handleException(res, 'deploy app to paas container error')
*/
}
//get image name by code package's fuzzy path user input
def getImageName(codePackagePath, pipeLogId) {
codeFileNoExt = getCodeFileNameNoExt(codePackagePath)
return formatImageName(codeFileNoExt, pipeLogId)
}
//get image name by code package's exact relative path
def getImageNameByExactPath(codeFilePath, pipeLogId) {
codeFileNoExt = getCodeFileNameNoExtByExactPath(codeFilePath)
return formatImageName(codeFileNoExt, pipeLogId)
}
//format image name
def formatImageName(codeFileNoExt, pipeLogId) {
return codeFileNoExt + '-te-msc-paas-gateway-' + pipeLogId + '-' + env.BUILD_ID
}
//get code package filename without extension by fuzzy path user input
def getCodeFileNameNoExt(codePackagePath) {
def codeFilePath = getCodeFilePath(codePackagePath)
return getCodeFileNameNoExtByExactPath(codeFilePath)
}
//get code package filename without extension by its exact relative path
def getCodeFileNameNoExtByExactPath(codeFilePath) {
def command = '''
#获取包名
codeFile=$(basename '''+codeFilePath+''')
#获取不含后缀的包名
echo ${codeFile%.*}
'''
return sh(returnStdout: true, script: command).trim()
}
//find code package and return relative path by fuzzy path user input
def getCodeFilePath(codePackagePath) {
def command = '''
#获取包文件
codePackageSearchName=$(basename "'''+codePackagePath+'''")
codePackageDirname=$(dirname "'''+codePackagePath+'''")
codeFile=$(find $codePackageDirname -name $codePackageSearchName)
#若模糊匹配的文件有多个,只取第一个
echo $codeFile | awk '{ print $1 }'
'''
return sh(returnStdout: true, script: command).trim()
}
// PAAS GET
def paasGet(url) {
def req = new URL(url).openConnection();
req.setRequestProperty("token","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZW1zY210In0.7Kno6QoIFmT8nQv-C2edlP514ekqy9pPNID_Vf__DPc")
def getRC = req.getResponseCode()
println "response code:"+getRC
def res;
if(getRC.equals(200)) {
res=req.getInputStream().getText()
def code = parseJsonText(res).code
println "response paas json code:"+code
if (code != '000000') {
error "ERROR: request " + url + " " + code + " error.\n" + res
}
println("result:\n" + res)
} else {
println "ERROR: request " + url + " " + getRC + " error."
error req.getInputStream().getText()
}
return parseJsonText(res).body.content
}
// PAAS POST
def paasPost(url, data) {
def req = new URL(url).openConnection()
req.setRequestMethod("POST")
req.setDoOutput(true)
req.setRequestProperty("token","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZW1zY210In0.7Kno6QoIFmT8nQv-C2edlP514ekqy9pPNID_Vf__DPc")
req.setRequestProperty("Content-Type", "application/json")
if (data != null) {
req.getOutputStream().write(data.getBytes("UTF-8"))
}
def postRC = req.getResponseCode()
println "response code:"+postRC
def body;
if(postRC.equals(200)) {
body = req.getInputStream().getText()
def code = parseJsonText(body).code
println "response paas json code:"+code
if (code != '000000') {
error "ERROR: request " + url + " " + code + " error.\n" + body
}
println("result:\n" + body)
}else{
println "ERROR: request " + url+ " " + postRC + " error."
error req.getInputStream().getText()
}
return parseJsonText(body).body.content
}
def parseJsonText(String json) {
return new groovy.json.JsonSlurperClassic().parseText(json)
}
def handleException(res, msg) {
def code = parseJsonText(res).code
if (code != '000000') {
error "ERROR: " + msg + " " + code + " \n" + res
}
}
node{
stage('GIT拉取代码') {
pipeLogId = addPipelineLog()
def pipeStageId = 1130561945160317727
try{
isTagOrBranch = 'TAG'
tagOrBranch = params.tagOrBranch
checkout([
$class: 'GitSCM',branches: [[name: "${params.tagOrBranch}"]],
userRemoteConfigs: [[url: 'http://10.145.196.76:9080/Shtel-PaaS-Platform/shtel-paas-service-gateway.git', credentialsId: 'c7887cee85a24fdfa8e372d317fa1d83']]
])
preExecuteEndPipelineStageCheck(pipeStageId)
sleep(unit: 'MILLISECONDS', time: 500)
sh(script: toUpdatePipelineLogCurlSh(currentBuild.currentResult, currentBuild.duration, getStageLog(currentBuild.rawBuild.log), pipeLogId, pipeStageId))
}catch(e){
result = 'FAILURE'
echo e.getMessage()
result = setPreExecuteResult(result, e.getMessage())
sleep(unit: 'MILLISECONDS', time: 500)
sh(script: toUpdatePipelineLogCurlSh(result, currentBuild.duration, getStageLog(currentBuild.rawBuild.log), pipeLogId, pipeStageId))
sh(script: toEndPipelineLogCurlSh(result, pipeLogId, params.projectVersionConfigId, params.publishLogId))
throw e
}
}
}
node{
stage('Maven构建') {
def mvnHome = tool 'maventool'
def pipeStageId = 1130561945160317728
try{
sh "${mvnHome}/bin/mvn -f pom.xml clean package -X -U -Dmaven.test.skip=true"
preExecuteEndPipelineStageCheck(pipeStageId)
sleep(unit: 'MILLISECONDS', time: 500)
sh(script: toUpdatePipelineLogCurlSh(currentBuild.currentResult, '', getStageLog(currentBuild.rawBuild.log), pipeLogId, pipeStageId))
}catch(e){
result = 'FAILURE'
echo e.getMessage()
result = setPreExecuteResult(result, e.getMessage())
sleep(unit: 'MILLISECONDS', time: 500)
sh(script: toUpdatePipelineLogCurlSh(result, '', getStageLog(currentBuild.rawBuild.log), pipeLogId, pipeStageId))
sh(script: toEndPipelineLogCurlSh(result, pipeLogId, params.projectVersionConfigId, params.publishLogId))
throw e
}
}
}
node{
stage('Paas构建镜像') {
def pipeStageId = 1130561945160317729
try{
ceEnvKey = 'test'
ceRemoteAddress = 'http://10.145.208.200:31601'
imgNamespaceName = 'te-msc-paas'
repoName = 'te-msc-paas-gateway'
codePackagePath = '*.tar.gz'
hasAdditionalFile = false
curlUploadFilePara = ''
dockerFileType = 'INPUT'
dockerfilePath = ''
dockerFileContent = '''FROM hub.paas/base/centos-jdk8-cn:latest
ADD *.tar.gz /usr/local/gateway-service/
RUN chmod u+x /usr/local/gateway-service/bin/run.sh
EXPOSE 8888
CMD '/usr/local/gateway-service/bin/run.sh' '''
def codeFilePath = getCodeFilePath(codePackagePath)
def tagName = getImageNameByExactPath(codeFilePath, pipeLogId)
buildPaasImage(ceRemoteAddress, imgNamespaceName, repoName, tagName, codeFilePath, hasAdditionalFile, curlUploadFilePara, dockerFileType, dockerfilePath, dockerFileContent)
imageId = recordImageInfo(ceEnvKey, imgNamespaceName, repoName, tagName, isTagOrBranch, tagOrBranch, pipeLogId, pipeStageId)
preExecuteEndPipelineStageCheck(pipeStageId)
sleep(unit: 'MILLISECONDS', time: 500)
sh(script: toUpdatePipelineLogCurlSh(currentBuild.currentResult, '', getStageLog(currentBuild.rawBuild.log), pipeLogId, pipeStageId))
}catch(e){
result = 'FAILURE'
echo e.getMessage()
result = setPreExecuteResult(result, e.getMessage())
sleep(unit: 'MILLISECONDS', time: 500)
sh(script: toUpdatePipelineLogCurlSh(result, '', getStageLog(currentBuild.rawBuild.log), pipeLogId, pipeStageId))
sh(script: toEndPipelineLogCurlSh(result, pipeLogId, params.projectVersionConfigId, params.publishLogId))
throw e
}
}
}
node{
stage('paas发布部署') {
def pipeStageId = 1130561945161366306
try{
deployPaasApp(pipeStageId, '*.tar.gz', pipeLogId)
preExecuteEndPipelineStageCheck(pipeStageId)
sleep(unit: 'MILLISECONDS', time: 500)
sh(script: toUpdatePipelineLogCurlSh(currentBuild.currentResult, '', getStageLog(currentBuild.rawBuild.log), pipeLogId, pipeStageId))
sh(script: toEndPipelineLogCurlSh(currentBuild.currentResult, pipeLogId, params.projectVersionConfigId, params.publishLogId))
}catch(e){
result = 'FAILURE'
echo e.getMessage()
result = setPreExecuteResult(result, e.getMessage())
sleep(unit: 'MILLISECONDS', time: 500)
sh(script: toUpdatePipelineLogCurlSh(result, '', getStageLog(currentBuild.rawBuild.log), pipeLogId, pipeStageId))
sh(script: toEndPipelineLogCurlSh(result, pipeLogId, params.projectVersionConfigId, params.publishLogId))
throw e
}
}
}
node{
stage('clean workspace') {
cleanWs()
}
}
转载于:https://www.cnblogs.com/fan-gx/p/11220221.html