java 单机接口限流处理方案
258
2022-11-02
Jenkins CD VM部署实践 02 根据版本文件下载制品
CD在早些团队里面,如果没有使用自动化的时候,开发给包给到运维,运维将包拷贝到服务器上面之后,通过一些脚本将包启动。
CD
之前CI将版本文件上传到了gitlab,现在要将这个版本文件下载下来,因为这里面存储着要发布的包的名称,所以CD流水线有两个步骤,一个是下载制品,另外一个步骤就是发布制品。
要从Gitlab里面去下载这个版本文件
添加选项参数:针对于不同的环境,选择要发布的环境
发布的主机
def projectId = 17def filePath = "myapp/release-${params.releaseVersion}.yaml"def branchName = "main"pipeline { agent any stages { stage('Hello') { steps { script{ response = GetRepoFile(projectId,"myapp%2frelease-1.1.1.yaml",branchName) println(response) } } } }}// 封装HTTPdef HttpReq(reqType, reqUrl,reqBody ){ def gitServer = " withCredentials([string(credentialsId: 'ecbcd399-da69-4802-8760-87a1c1ff58a1', variable: 'GITLABTOKEN')]) { response = acceptType: 'APPLICATION_JSON_UTF8', consoleLogResponseBody: true, contentType: 'APPLICATION_JSON_UTF8', customHeaders: [[maskValue: false, name: 'PRIVATE-TOKEN', value: "${GITLABTOKEN}"]], "${reqType}", url: "${gitServer}/${reqUrl}", wrapAsMultipart: false, requestBody: "${reqBody}" } return response} //获取文件内容def GetRepoFile(projectId,filePath, branchName ){ //GET /projects/:id/repository/files/:file_path/raw apiUrl = "/projects/${projectId}/repository/files/${filePath}/raw?ref=${branchName}" response = HttpReq('GET', apiUrl, "") return response.content }
"myapp%2frelease-1.1.1.yaml" 这里有个转义符代表/,如果定义为变量就这样写:def filePath = "myapp%2frelease-1.1.1.yaml" 或者def filePath = "myapp%2frelease-${params.releaseVersion}.yaml"
可以看到上面获取到了制品信息,现在就是去下载制品了
def projectId = 17def filePath = "myapp%2frelease-${params.releaseVersion}.yaml"def branchName = "main"pipeline { agent { label 'build' } stages { stage('GetArtifactUrl') { steps { script{ response = GetRepoFile(projectId,filePath,branchName) //println(response) yamlData = readYaml text: """${response}""" env.artifactUrl = yamlData.artifact println(env.artifactUrl) } } } stage('DownloadArtifact') { steps { script{ withCredentials([usernamePassword(credentialsId: 'ff93f4bf-9d8c-4fc2-bccd-3e614f10d643', passwordVariable: 'passwd', usernameVariable: 'user')]) { sh """ wget ----${env.artifactUrl} """ } } } } }}// 封装HTTPdef HttpReq(reqType, reqUrl,reqBody ){ def gitServer = " withCredentials([string(credentialsId: 'ecbcd399-da69-4802-8760-87a1c1ff58a1', variable: 'GITLABTOKEN')]) { response = acceptType: 'APPLICATION_JSON_UTF8', consoleLogResponseBody: true, contentType: 'APPLICATION_JSON_UTF8', customHeaders: [[maskValue: false, name: 'PRIVATE-TOKEN', value: "${GITLABTOKEN}"]], "${reqType}", url: "${gitServer}/${reqUrl}", wrapAsMultipart: false, requestBody: "${reqBody}" } return response} //获取文件内容def GetRepoFile(projectId,filePath, branchName ){ //GET /projects/:id/repository/files/:file_path/raw apiUrl = "/projects/${projectId}/repository/files/${filePath}/raw?ref=${branchName}" response = HttpReq('GET', apiUrl, "") return response.content }
[root@jenkins-agent workspace]# cd nexus/[root@jenkins-agent nexus]# lsnexus-api-test nexus-chajian-download nexus-chajian-upload nexus-deploy-mvn release-file@tmp test@tmpnexus-api-test@tmp nexus-chajian-download@tmp nexus-chajian-upload@tmp release-file test[root@jenkins-agent nexus]# cd test[root@jenkins-agent test]# lsacmp-myapp-service-1.1.1.jar
制品拿到之后就是发布了
前端项目编译完之后是一个静态的资源文件,是一个压缩包,相对于拷贝到nginx服务器的站点目录下面,然后解压就ok了。后端项目就有一个脚本专门启动,后端项目需要写服务启动脚本。
扩展: 如何清除工作目录? 安装Workspace Cleanup插件。在Pipeline 的Post中的always添加CleanWs()
用来在build开始前或build完成后清理workspace。
post { always{ script { cleanWs() } } }
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~