代码拉取完成,页面将自动刷新
//git凭证ID
def git_auth = "83434be1-d506-48e3-8e67-eb9aef6c558b"
//git的url地址
def git_url = "https://gitee.com/yuankaiqiang/woniuedu.git"
//镜像的版本号
def tag = "latest"
//Harbor的url地址
def harbor_url = "47.108.76.15:85"
//镜像库项目名称
def harbor_project = "woniuedu"
//Harbor的登录凭证ID
def harbor_auth = "681e8dba-0253-46a4-8dc8-319f54d4b5ac"
//harbor位置
//def publish_server = "woniuedu"
node {
//获取当前选择的项目名称
def selectedProjectNames = "${project_name}".split(",")
//获取当前选择的服务器名称
//def selectedServers = "${publish_server}".split(",")
stage('拉取代码') {
checkout([$class: 'GitSCM', branches: [[name: "*/${branch}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]]])
}
// stage('代码审查') {
// for(int i=0;i<selectedProjectNames.length;i++){
// //tensquare_eureka_server@10086
// def projectInfo = selectedProjectNames[i];
// //当前遍历的项目名称
// def currentProjectName = "${projectInfo}".split("@")[0]
// //当前遍历的项目端口
// def currentProjectPort = "${projectInfo}".split("@")[1]
//
// //定义当前Jenkins的SonarQubeScanner工具
// def scannerHome = tool 'sonar-scanner'
// //引用当前JenkinsSonarQube环境
// withSonarQubeEnv('sonarqube') {
// sh """
// cd ${currentProjectName}
// ${scannerHome}/bin/sonar-scanner
// """
// }
// }
// }
stage('编译,安装公共子工程') {
sh "mvn -f woniuedu-commons clean install"
}
stage('编译,打包网关微工程,上传镜像') {
def gatewayPathSelect ="${gatewayPathSelect}"
if( gatewayPathSelect =="api-gateway"){
//进入网关包
def gatewayPath="woniuedu-infrastructure"
def currentProjectName="api-gateway"
//打包
sh """
cd ${gatewayPath}
mvn -f ${currentProjectName} clean package dockerfile:build """
//定义镜像名称
def imageName = "${currentProjectName}:${tag}"
//对镜像打上标签
sh "docker tag ${imageName} ${harbor_url}/${harbor_project}/${imageName}"
//把镜像推送到Harbor
withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')]) {
//登录到Harbor
sh "docker login -u ${username} -p ${password} ${harbor_url}"
//镜像上传
sh "docker push ${harbor_url}/${harbor_project}/${imageName}"
sh "echo 镜像上传成功"
}
def currentServerName = "haonan"
def currentProjectPort ="8222"
sh "echo 网关部署应用"
//部署应用
sshPublisher(publishers: [sshPublisherDesc(configName: "${currentServerName}", transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/root/jenkins_shell/deploy.sh $harbor_url $harbor_project $currentProjectName $tag $currentProjectPort", execTimeout: 480000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
sh "echo 网关部署完毕"
}else{
sh "echo 不打包编译网关"
}
}
stage('编译,打包微服务工程,上传镜像') {
for(int i=0;i<selectedProjectNames.length;i++){
//tensquare_eureka_server@10086
def projectInfo = selectedProjectNames[i];
def projectInfom = "woniuedu-service";
//当前遍历的项目名称
def currentProjectName = "${projectInfo}".split("@")[0]
//当前遍历的项目端口
def currentProjectPort = "${projectInfo}".split("@")[1]
//打包
sh """
cd ${projectInfom}
mvn -f ${currentProjectName} clean package dockerfile:build """
//定义镜像名称
def imageName = "${currentProjectName}:${tag}"
//对镜像打上标签
sh "docker tag ${imageName} ${harbor_url}/${harbor_project}/${imageName}"
//把镜像推送到Harbor
withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')]) {
//登录到Harbor
sh "docker login -u ${username} -p ${password} ${harbor_url}"
//镜像上传
sh "docker push ${harbor_url}/${harbor_project}/${imageName}"
sh "echo 镜像上传成功"
}
// //遍历所有服务器,分别部署
// for(int j=0;j<selectedServers.length;j++){
// //获取当前遍历的服务器名称
// def currentServerName = selectedServers[j]
// //加上的参数格式:--spring.profiles.active=eureka-server1/eureka-server2
// def activeProfile = "--spring.profiles.active="
// //根据不同的服务名称来读取不同的Eureka配置信息
// if(currentServerName=="master_server"){
// activeProfile = activeProfile+"eureka-server1"
// }else if(currentServerName=="slave_server"){
// activeProfile = activeProfile+"eureka-server2"
// }
def currentServerName = "haonan"
sh "echo 部署应用"
//部署应用
sshPublisher(publishers: [sshPublisherDesc(configName: "${currentServerName}", transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/root/jenkins_shell/deploy.sh $harbor_url $harbor_project $currentProjectName $tag $currentProjectPort ", execTimeout: 480000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
// }
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。