• jenkins-自动化打包部署


    环境:

            centos 7.2或者更新

            rmp包:官方下载地址 Redhat Jenkins Packages

            java-1.8.0

    安装:

    1. [root@jenkins ~]# yum install wget  java-1.8.0 -y
    2. [root@jenkins ~]# cd /var/opt/
    3. [root@jenkins opt]# wget https://pkg.jenkins.io/redhat-stable/jenkins-2.176.2-1.1.noarch.rpm
    4. [root@jenkins opt]# yum install ./jenkins-2.176.2-1.1.noarch.rpm -y

    配置:jenkins 配置文件 /etc/sysconfig/jenkins  ,可以根据需求自行修改

    1. [root@jenkins opt]# grep '^[^#]' /etc/sysconfig/jenkins 
    2. JENKINS_HOME="/data/jenkins"        #jenkins的数据目录
    3. JENKINS_JAVA_CMD=""
    4. JENKINS_USER="jenkins"
    5. JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"
    6. JENKINS_PORT="8080"                #jenkins 通过web访问的端口
    7. JENKINS_LISTEN_ADDRESS=""
    8. JENKINS_HTTPS_PORT=""
    9. JENKINS_HTTPS_KEYSTORE=""
    10. JENKINS_HTTPS_KEYSTORE_PASSWORD=""
    11. JENKINS_HTTPS_LISTEN_ADDRESS=""
    12. JENKINS_DEBUG_LEVEL="5"
    13. JENKINS_ENABLE_ACCESS_LOG="no"
    14. JENKINS_HANDLER_MAX="100"
    15. JENKINS_HANDLER_IDLE="20"
    16. JENKINS_ARGS=""
    1. mkdir /data/jenkins -pv
    2. chown jenkins.jenkins /data/jenkins

    访问web 并进行配置

    稍等一会,就可以正常登录了

    根据需要安装自定义插件,本次选择是推荐安装

    等待安装,估计需要5分钟左右,如果中间有失败,重试就行,安装完成之后,会自动跳入如下页面,然后自己创建用户,或者直接使用admin 账户

    开始登录:

    登录之后,安装一些插件,点击系统管理,进入 插件管理,选择可选插件,然后过滤下载

    Maven Release Plug-in

    Publish Over SSH

    Multijob

    安装之后,点击系统管理,进入 全局工具配置

    配置jdk

    配置maven

    配置远程服务器信息 Publish over SSH

        系统管理  系统设置,然后搜索 Publish over SSH

        填写远程机器的登录信息,填写之后 一定要测试一下,是否认证成功

    如果有需要用到的全局变量,也可以在系统设置里面配置,如下

    准备工作差不多了,现在需要创建一个maven 任务,测试一下

    这个定时删除旧的构建,还可以节省磁盘空间

    构建触发器,根据需要选择,默认为第一个选择


    下面说下简单的pipline 流水线

    1. pipeline {
    2.     agent any 
    3. environment {
    4.         ios="ios"
    5. android="android"
    6.     }
    7.     stages {
    8.         
    9. stage("清理之前打包的热更资源文件") {
    10. steps {
    11. script { 
    12. sh label: 'removetars', returnStdout: true, script: 'rm -rf target aliPjo RainVersion'
    13. }
    14. }
    15. }
    16. stage('请选择版本[正式版|开发板]'){
    17. steps {
    18. script {
    19. def result="product\ndebug"
    20. def userInput = input(id'userInput', message: '请选择版本[正式版|开发版]'
    21. parameters: [[$class'ChoiceParameterDefinition', defaultValue: 'strDef'
    22. description:'product:正式版\ndebug:开发版', name:'打包热更资源分支', choices: "${result}"
    23. ]) 
    24.  
    25. if ( userInput =="debug" ) {
    26. ios="iosdebug"
    27. android="androiddebug"
    28. }else {
    29. ios="ios"
    30. android="android"
    31. }
    32.  
    33. }
    34. }
    35. }
    36.         stage('请输入要更新的 IOS 客户端版本') { 
    37. steps { 
    38.         
    39. script { 
    40.   def  result = sh(returnStdout: true, script: "sh /data/jenkins/get.cliet.version.sh $ios").trim()
    41.   def userInput = input(id'userInput', message: '请输入要更新的 IOS 客户端版本'
    42.   parameters: [[$class'ChoiceParameterDefinition', defaultValue: 'strDef'
    43.    description:'...', name:'客户端版本', choices: "${result}"
    44.   ]) 
    45. checkout([$class'SubversionSCM', additionalCredentials: [], 
    46. excludedCommitMessages: ''
    47. excludedRegions: ''
    48. excludedRevprop: ''
    49. excludedUsers: ''
    50. filterChangelog: false
    51. ignoreDirPropChanges: false
    52. includedRegions: ''
    53. locations: [[cancelProcessOnExternalsFail: true
    54. credentialsId: 'e433b9f7-72aa-41c3-add0-cecss3ba7398'
    55. depthOption: 'infinity'
    56. ignoreExternalsOption: true
    57. local"./aliPjo/$ios/${userInput}"
    58. remote: "svn://svn.kp.aliyu.com/hotclient/aliPjo/$ios/${userInput}"]], 
    59. quietOperation: true
    60. workspaceUpdater: [$class'UpdateUpdater']])
    61. checkout([$class'SubversionSCM', additionalCredentials: [], 
    62. excludedCommitMessages: ''
    63. excludedRegions: ''
    64. excludedRevprop: ''
    65. excludedUsers: ''
    66. filterChangelog: false
    67. ignoreDirPropChanges: false
    68. includedRegions: ''
    69. locations: [[cancelProcessOnExternalsFail: true
    70. credentialsId: 'e433b9f7-72aa-41c3-add0-cecss3ba7398'
    71. depthOption: 'files'
    72. ignoreExternalsOption: true
    73. local"./RainVersion/$ios/"
    74. remote: "svn://svn.kp.aliyu.com/hotclient/aliPjo/$ios/"]], 
    75. quietOperation: true
    76. workspaceUpdater: [$class'UpdateUpdater']])
    77. }
    78. stage('请输入要更新的 Android 客户端版本') { 
    79. steps { 
    80.         
    81. script { 
    82.  
    83.   def  result = sh(returnStdout: true, script: "sh /data/jenkins/get.cliet.version.sh $android").trim()
    84.   def userInput = input(id'userInput', message: '请输入要更新的 Android 客户端版本'
    85.   parameters: [[$class'ChoiceParameterDefinition', defaultValue: 'strDef'
    86.    description:'...', name:'客户端版本', choices: "${result}"
    87.   ]) 
    88.   println(userInput); //Use this value to branch to different logic if needed 
    89.  
    90. checkout([$class'SubversionSCM', additionalCredentials: [], 
    91. excludedCommitMessages: ''
    92. excludedRegions: ''
    93. excludedRevprop: ''
    94. excludedUsers: ''
    95. filterChangelog: false
    96. ignoreDirPropChanges: false
    97. includedRegions: ''
    98. locations: [[cancelProcessOnExternalsFail: true
    99. credentialsId: 'e433b9f7-72aa-41c3-add0-cecss3ba7398'
    100. depthOption: 'infinity'
    101. ignoreExternalsOption: true
    102. local"./aliPjo/$android/${userInput}"
    103. remote: "svn://svn.kp.aliyu.com/hotclient/aliPjo/$android/${userInput}"]], 
    104. quietOperation: true
    105. workspaceUpdater: [$class'UpdateUpdater']])
    106. checkout([$class'SubversionSCM', additionalCredentials: [], 
    107. excludedCommitMessages: ''
    108. excludedRegions: ''
    109. excludedRevprop: ''
    110. excludedUsers: ''
    111. filterChangelog: false
    112. ignoreDirPropChanges: false
    113. includedRegions: ''
    114. locations: [[cancelProcessOnExternalsFail: true
    115. credentialsId: 'e433b9f7-72aa-41c3-add0-cecss3ba7398'
    116. depthOption: 'files'
    117. ignoreExternalsOption: true
    118. local"./RainVersion/$android/"
    119. remote: "svn://svn.kp.aliyu.com/hotclient/aliPjo/$android/"]], 
    120. quietOperation: true
    121. workspaceUpdater: [$class'UpdateUpdater']])
    122. }
    123. }
    124. stage("打包热更资源文件") {
    125. steps {
    126. script { 
    127. sh label: 'tarhotclient', returnStatus: true, script: "[ ! -f RainVersion/$android/RainVersion.json ] && exit 1"
    128. sh label: 'tarhotclient', returnStatus: true, script: "[ ! -f RainVersion/$ios/RainVersion.json ] && exit 1"
    129. sh label: 'tarhotclient', returnStatus: true, script: "\\cp RainVersion/$android/RainVersion.json aliPjo/$android/ "
    130. sh label: 'tarhotclient', returnStatus: true, script: "\\cp RainVersion/$ios/RainVersion.json aliPjo/$ios/ "
    131. sh label: 'tarhotclient', returnStdout: true, script: "[ ! -d target ] && mkdir -pv target"
    132. sh label: 'tarhotclient', returnStdout: true, script: "tar  --exclude='*.svn' -zcvf target/hotclient.tar.gz aliPjo"
    133. }
    134. }
    135. }
    136. stage("传输文件到管理机并更新"){
    137. steps{
    138. script{
    139. sshPublisher(publishers: [sshPublisherDesc(configName: 'DevOps'
    140. transfers: [sshTransfer(cleanRemote: false, excludes: ''
    141. execCommand: 'sh /data/dev.scripts/update_hotclient.sh'
    142. execTimeout: 120000, 
    143. flatten: false
    144. makeEmptyDirs: false
    145. noDefaultExcludes: false
    146. patternSeparator: '[, ]+'
    147. remoteDirectory: '/data/updateapps/'
    148. remoteDirectorySDF: false
    149. removePrefix: 'target/'
    150. sourceFiles: 'target/hotclient.tar.gz')], 
    151. usePromotionTimestamp: false
    152. useWorkspaceInPromotion: false
    153. verbose: false)])
    154. }
    155. }
    156. }
    157.         
    158.     }
    159. }

  • 相关阅读:
    【定向征文活动】2023年深圳1024开发者城市聚会活动参会感想征文
    算法训练 第四周
    STL中 Map 的基本用法
    Vue项目中使用element-plus UI库-并对下拉搜索框样式修改-el-select代码封装
    力扣(122.1049)补7.29
    [附源码]SSM计算机毕业设计学生档案管理系统JAVA
    延伸产业链推进水稻循环经济 国稻种芯集团谋定益海嘉里合作
    急诊预检分诊管理系统的设计与实现
    React面试题总结
    软件测试面试题-一个前后端都能修改的bug,应该由谁修改?
  • 原文地址:https://blog.csdn.net/ly1358152944/article/details/126447428