本人菜鸟一枚,此文仅做记录,大佬勿喷。
node {
stage('拉取gitee代码') {
git branch: "${BRANCH}", credentialsId: '密匙', url: 'gitee地址'
}
stage('maven构建项目') {
sh "mvn clean install -pl ${"${SERVICE}"} -am -amd -Pdev -Dmaven.test.skip=true"
}
stage('jar包上传,构建docker镜像运行') {
def item = "${SERVICE}".split(",")
println item.toString()
for(int i=0;i<item.length;i++){
uploadFile(item[i])
stage("${item[i]}服务运行..."){
uploadFile(item[i])
}
}
}
}
/*上传文件*/
def uploadFile(def name){
String cmd = "cd /www/wwwroot/cloud-shopping && docker-compose up -d --force-recreate --build ${name}"
String sourceFilePath = "${name}/**/*.jar,${name}/Dockerfile,docker-compose.yml"
println sourceFilePath
sshPublisher(
publishers: [
sshPublisherDesc(
configName: "$SSH_NAME",
transfers: [sshTransfer(
cleanRemote: false,
excludes: '',
execCommand: cmd,
execTimeout: 120000,
flatten: false,
makeEmptyDirs: false,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: 'cloud-shopping',
remoteDirectorySDF: false,
removePrefix: '',
sourceFiles: sourceFilePath
)],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: true
)
]
)
}