代码拉取完成,页面将自动刷新
同步操作将从 SmallDragon/jenkins-1-tensquare_parent 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// git凭证id
def git_auth = "a4660d7a-dd89-47c1-b543-4369a0b5aa84"
// git的url地址
def git_url = "git@192.168.172.148:my_dev_group/tensquare_back.git"
def tag = "latest"
def harbor_url = "192.168.172.148:85"
def harbor_project = "tensquare"
def harbor_auth = "3ba2837c-d0bb-493a-83e3-817a9e8983ec"
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++){
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 tensquare_common clean install"
}
stage('编译,打包微服务,并且构建镜像') {
for(int i = 0;i<selectedProjectNames.length;i++){
def projectInfo = selectedProjectNames[i]
def currentProjectName = "${projectInfo}".split("@")[0]
def currentProjectPort = "${projectInfo}".split("@")[1]
// 项目编译、打包、构建docker镜像
sh "mvn -f ${currentProjectName} clean package dockerfile:build"
def imageName = "${currentProjectName}:${tag}"
//删除之前tag过的dockers镜像
sh "docker rmi ${harbor_url}/${harbor_project}/${imageName}"
//打上docker标签
sh "docker tag ${imageName} ${harbor_url}/${harbor_project}/${imageName}"
// 登陆docker仓库、上传项目docker镜像
withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')]) {
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 currentServer = selectedServers[j]
def activeProfile = "--spring.profiles.active="
def ipAddr = "--eureka.instance.ip-address="
if(currentServer == "master_server_150"){
activeProfile = activeProfile + "eureka-server1"
ipAddr = ipAddr + "192.168.172.150"
}else if(currentServer == "slave_server_151"){
activeProfile = activeProfile + "eureka-server2"
ipAddr = ipAddr + "192.168.172.151"
}
// 调用部署服务器的脚本,执行删除容器和镜像、拉取镜像、运行镜像
sshPublisher(publishers: [sshPublisherDesc(configName: "${currentServer}", transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/opt/jenkins_shell/deployCluster.sh $harbor_url $harbor_project $currentProjectName $tag $currentProjectPort $activeProfile $ipAddr", execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。