pipeline {
agent any
tools {
maven 'MAVEN3'
jdk 'JDK1.8'
}
environment {
// 项目代码拉取
git_path = "http://3.1.101.36:3000/credit-rebuild/bank-credit-sy.git"
git_auth_id = "cfa69b9a-5c02-4992-b09a-6dd4e757700c"
git_branch = "master"
}
parameters {
extendedChoice name: 'project_names', type: 'PT_CHECKBOX', description: '请勾选所要发布的项目模块', quoteValue: false, saveJSONParameterToFile: false,
value: 'account-server,account-api',
descriptionPropertyValue: 'account-server,account-api',
visibleItemCount: 2, multiSelectDelimiter: ',', defaultValue: 'account-server'
}
stages {
stage('项目代码拉取') {
steps {
deleteDir() // clean up current workspace
// sh "rm -rf /root/.m2"
checkout([$class: 'GitSCM', branches: [[name: "${git_branch}"]], extensions: [],
userRemoteConfigs: [[credentialsId: "${git_auth_id}", url: "${git_path}"]]])
}
}
stage('项目构建') {
steps {
withMaven(jdk: 'JDK1.8', maven: 'MAVEN3') {
sh '''
java -version
mvn -version
mvn clean install -Dmaven.test.skip=true
'''
}
}
}
stage('项目发布') {
steps {
script {
for (project_name in project_names.tokenize(',')) {
// 项目代码发布
def target_dir = "${JOB_NAME}/${project_name}/target"
def target_file = "*.jar"
def source_file = "${target_dir}/${target_file}"
def remove_prefix = "${target_dir}"
def remote_server = "weblogic1"
def remote_path = "/opt/ccms-auto-deploy"
def remote_dir = "${JOB_NAME}/${project_name}"
def remote_cmd = "/bin/bash /data/scripts/chmod.sh; cd ${remote_path}/${remote_dir}; ps aux |grep ${project_name}.*.jar|grep -v grep|awk '{print \$2}'|xargs kill -9; source /etc/profile; nohup java -jar `ls ${project_name}-*-SNAPSHOT.jar -1t|head -n1` >> ${project_name}.log &"
sshPublisher(publishers: [sshPublisherDesc(configName: "${remote_server}",
transfers: [sshTransfer(execCommand: "${remote_cmd}",
remoteDirectory: "${remote_dir}", removePrefix: "${remove_prefix}", sourceFiles: "${source_file}")],)])
}
}
}
}
}
}
jenkins pipeline 参数化构建复选框for循环使用
最新推荐文章于 2024-05-27 07:00:00 发布