1 Star 0 Fork 0

YingBo.Dai/skycity-cloud

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Jenkinsfile 5.24 KB
一键复制 编辑 原始数据 按行查看 历史
YingBo.Dai 提交于 2021-12-21 21:17 . update jenkinsfile
//镜像的版本号
def tag = "latest"
//def version = "1.${env.BUILD_ID}"
def version = "1.0"
//Harbor的url地址
def harbor_url = "47.119.137.154"
def aliyun_url = "registry-vpc.cn-shenzhen.aliyuncs.com"
def registry = "${aliyun_url}/skycity-hub"
//分支名称
def branch = "master"
//Harbor的登录凭证ID
def harbor_auth = "86beb97d-7de6-4dc2-ab10-bc199d9eda97"
node {
//获取当前选择的项目名称
def selectedProjectNames = "${project_name}".split(",")
stage('Pull Code') {
checkout([$class: 'GitSCM', branches: [[name: '*/${branch}']], extensions: [], userRemoteConfigs: [[credentialsId: '8a7c0bcf-f690-47cc-ace6-3907144f9b05', url: 'https://gitee.com/lyyb2002/skycity-cloud']]])
}
stage('代码审查') {
sh "echo ${selectedProjectNames}"
// 定义当前Jenkins的SonarQubeScanner工具
// def scannerHome = tool 'sonarqube-scanner'
// 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]
//
// //引用当前JenkinsSonarQube环境
// withSonarQubeEnv('sonarqube') {
// sh """
// cd ${currentProjectName}
// ${scannerHome}/bin/sonar-scanner
// """
// }
// }
}
stage('编译,安装公共子工程') {
sh "mvn -f skycity-common clean install"
}
stage('编译,生成镜像') {
for(int i=0;i<selectedProjectNames.length;i++){
//tensquare_eureka_server@10086
def projectInfo = selectedProjectNames[i];
//当前遍历的项目名称
def currentProjectName = "${projectInfo}".split("@")[0]
sh "mvn clean package -Pprod -Dmaven.test.skip=true -f ${currentProjectName} dockerfile:build"
}
}
stage('上传镜像') {
// sh "docker login -u lyyb2001 -p ptT26sLQ ${harbor_url}"
sh "docker login --username lyyb2001@163.com --password safe1128gogo ${aliyun_url}"
for(int i=0;i<selectedProjectNames.length;i++){
def projectInfo = selectedProjectNames[i];
//当前遍历的项目名称
def currentProjectName = "${projectInfo}".split("@")[0]
if(currentProjectName.indexOf("/")==-1){
//定义镜像名称
def imageName = "${currentProjectName}:${tag}"
//给镜像打标签
sh "docker tag ${imageName} ${registry}/${currentProjectName}:${version}"
//上传镜像
sh "docker push ${registry}/${currentProjectName}:${version}"
//删除本地镜像
sh "docker rmi -f ${imageName}"
sh "docker rmi -f ${registry}/${currentProjectName}:${version}"
}else{
def name = currentProjectName.substring(currentProjectName.indexOf("/")+1,currentProjectName.length())
def imageName = "${name}:${tag}"
//给镜像打标签
sh "docker tag ${imageName} ${registry}/${name}:${version}"
//上传镜像
sh "docker push ${registry}/${name}:${version}"
//删除本地镜像
sh "docker rmi -f ${imageName}"
sh "docker rmi -f ${registry}/${name}:${version}"
}
}
}
stage('应用部署') {
for(int i=0;i<selectedProjectNames.length;i++){
def projectInfo = selectedProjectNames[i];
// 当前遍历的项目端口
def currentProjectName = "${projectInfo}".split("@")[0]
def currentProjectPort = "${projectInfo}".split("@")[1]
if(currentProjectName.indexOf("/")==-1){
sshPublisher(publishers: [sshPublisherDesc(configName: 'server2', transfers: [sshTransfer(cleanRemote: false, excludes: '',
execCommand: "/root/deploy.sh ${currentProjectName} ${version} ${currentProjectPort}",
execTimeout: 720000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false,
removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}else{
def name = currentProjectName.substring(currentProjectName.indexOf("/")+1,currentProjectName.length())
def commandToExec = "/root/deploy.sh ${name} ${version} ${currentProjectPort}"
sshPublisher(publishers: [sshPublisherDesc(configName: 'server2', transfers: [sshTransfer(cleanRemote: false, excludes: '',
execCommand: "${commandToExec}",
execTimeout: 720000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false,
removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lyyb2002/skycity-cloud.git
git@gitee.com:lyyb2002/skycity-cloud.git
lyyb2002
skycity-cloud
skycity-cloud
master

搜索帮助