您的位置:首页 > 文旅 > 旅游 > Jenkins配置weblogic自动发版--示例

Jenkins配置weblogic自动发版--示例

2024/12/23 16:36:52 来源:https://blog.csdn.net/wangshui898/article/details/140655531  浏览:    关键词:Jenkins配置weblogic自动发版--示例

Pipeline内容

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 anytools {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()  // clean up current workspacecheckout([$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 -versionmvn -versionmvn clean install -Dmaven.test.skip=true'''}}else {withMaven(jdk: 'JDK1.8', maven: 'MAVEN3') {sh '''java -versionmvn -versionmvn clean install -Dmaven.test.skip=true'''}}}}}stage('项目发布') {when {environment name: 'Action', value: 'Deploy'}steps {script{for (wls_server in WLS_Servers.tokenize(',')) {// for (wls_target in WLS_Targets.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(',')) {// for (wls_target in WLS_Targets.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}")],)])// }}}}}}
}

脚本内容

#!/bin/bash
wls_classpath=/home/weblogic/Oracle/Middleware/wlserver/server/lib/action=$1
appName=$2
warName=$3
target=$4wlsaddr="t3://172.16.20.71:7001"
wlsuser=weblogic
wlspasswd=weblogic1save_files=5deploy() {
java -cp ${wls_classpath}/weblogic.jar weblogic.Deployer -adminurl $wlsaddr -user $wlsuser -password $wlspasswd -name $appName -deploy -targets $target -source /home/weblogic/version/$warName
}delete() {
java -cp ${wls_classpath}/weblogic.jar weblogic.Deployer -adminurl $wlsaddr -user $wlsuser -password $wlspasswd -name $appName -undeploy
}cleanWar() {
cd  /home/weblogic/version
while true;
dofile_count=`ls -1t  ${warName}.*|wc -l`if [ ${file_count} -gt ${save_files} ];thenls -1t ${warName}.*|tail -1|xargs rm -felsebreak;fi
done
}
if [ "$action" == "deploy" ];thendeployif [ "$?" -eq "0" ];thencd /home/weblogic/version; mv $warName $warName.bak_$(date '+%Y%m%d%H%M')ficleanWar
elif [ "$action" == "delete" ];thendelete
fi

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com