1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
| properties([parameters([[$class: 'CascadeChoiceParameter', choiceType: 'PT_CHECKBOX', description: '选择 受管服务器', filterLength: 1, filterable: false, name: 'WLS_Targets', randomName: 'choice-parameter-173347495550024', referencedParameters: 'Action', script: [$class: 'GroovyScript', fallbackScript: [classpath: [], oldScript: '', sandbox: false, script: 'return ["Envrionment Undefined"]'], script: [classpath: [], oldScript: '', sandbox: false, script: '''if (Action.equals("Deploy")) { return ["AdminServer:selected","serverA","serverB","serverC"] } ''']]]])])
pipeline { agent any tools { maven 'MAVEN3' jdk 'JDK1.8' } environment { svn_path = "svn://172.16.20.70/ccms-project" svn_auth_id = "cdb6584d-9f9b-4ecb-890e-a15081c0abca" appName = "ccms-test" warName = "water-test-1.0-SNAPSHOT.war" } parameters { choice choices: ['Deploy', 'Delete'], description: '选择 发布项目|删除项目', name: 'Action' extendedChoice name: 'MavenBuild', type: 'PT_RADIO', description: '发版选项: 是否进行全新的Maven构建; 删除项目不需要勾选', quoteValue: false, saveJSONParameterToFile: false, value: 'Yes,Clean', descriptionPropertyValue: '进行Maven构建并发版,清除Maven缓存全新构', visibleItemCount: 5, multiSelectDelimiter: ',', defaultValue: 'Yes' extendedChoice name: 'WLS_Servers', type: 'PT_CHECKBOX', description: '请选择weblogic服务器', quoteValue: false, saveJSONParameterToFile: false, value: 'weblogic1,weblogic2,weblogic3,weblogic4', descriptionPropertyValue: '172.16.20.70,172.16.20.71,172.16.20.72,172.16.20.73', visibleItemCount: 10, multiSelectDelimiter: ',', defaultValue: 'weblogic1' } stages { stage('项目代码拉取') { when { anyOf { allOf { environment name: 'Action', value: 'Deploy' environment name: 'MavenBuild', value: 'Yes' } allOf { environment name: 'Action', value: 'Deploy' environment name: 'MavenBuild', value: 'Clean' } } } steps{ script { if ( env.Action == "Deploy" && env.MavenBuild == "Clean" ) { deleteDir() checkout([$class: 'SubversionSCM', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: "${svn_auth_id}", depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${svn_path}"]], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater']]) } else { checkout([$class: 'SubversionSCM', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: "${svn_auth_id}", depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "${svn_path}"]], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater']]) } } } } stage('项目构建') { when { anyOf { allOf { environment name: 'Action', value: 'Deploy' environment name: 'MavenBuild', value: 'Yes' } allOf { environment name: 'Action', value: 'Deploy' environment name: 'MavenBuild', value: 'Clean' } } } steps { script { if ( env.MavenBuild == "Clean" ) { sh "rm -rf /root/.m2" withMaven(jdk: 'JDK1.8', maven: 'MAVEN3') { sh ''' java -version mvn -version mvn clean install -Dmaven.test.skip=true ''' } } else { withMaven(jdk: 'JDK1.8', maven: 'MAVEN3') { sh ''' java -version mvn -version mvn clean install -Dmaven.test.skip=true ''' } } } } } stage('项目发布') { when { environment name: 'Action', value: 'Deploy' } steps { script{ for (wls_server in WLS_Servers.tokenize(',')) { def target_dir = "target" def target_file = "${warName}" def source_file = "${target_dir}/${target_file}" def remove_prefix = "target" def remote_dir = "version" def remote_cmd = "cd /home/weblogic/; /bin/sh ccms-deploy.sh deploy ${appName} ${warName} ${WLS_Targets} >> version/version-deploy.log" sshPublisher(publishers: [sshPublisherDesc(configName: "${wls_server}", transfers: [sshTransfer(execCommand: "${remote_cmd}", remoteDirectory: "${remote_dir}", removePrefix: "${remove_prefix}", sourceFiles: "${source_file}")],)]) } } } } stage('项目删除') { when { environment name: 'Action', value: 'Delete' } steps { script{ for (wls_server in WLS_Servers.tokenize(',')) { def target_dir = "" def target_file = "" def source_file = "" def remove_prefix = "" def remote_dir = "" def remote_cmd = "cd /home/weblogic/; /bin/sh ccms-deploy.sh delete ${appName} >> version/version-delete.log" sshPublisher(publishers: [sshPublisherDesc(configName: "${wls_server}", transfers: [sshTransfer(execCommand: "${remote_cmd}", remoteDirectory: "${remote_dir}", removePrefix: "${remove_prefix}", sourceFiles: "${source_file}")],)]) } } } } } }
|