3 Star 0 Fork 0

落夏/woniuedu

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Jenkinsfile 7.00 KB
一键复制 编辑 原始数据 按行查看 历史
落夏 提交于 2022-05-05 16:17 . 修改jenkinsfile 文件
//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)])
// }
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/yuankaiqiang/woniuedu.git
git@gitee.com:yuankaiqiang/woniuedu.git
yuankaiqiang
woniuedu
woniuedu
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385