You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.3 KiB
58 lines
2.3 KiB
def buildService(serverName){ |
|
docker.withRegistry('https://registry.internal.jumaiyx.cn', 'docker-registry-internal-backend') { |
|
def img = docker.build("jm/$serverName:${env.BUILD_ID}",".") |
|
img.push() |
|
} |
|
} |
|
|
|
pipeline { |
|
agent any |
|
|
|
environment { |
|
// 服务名 |
|
SERVER_NAME = 'room-hot-compute-job' |
|
// 镜像名称,对应K8S_FILE里面Deployment.containers的name |
|
IMAGE_NAME = 'room-hot-compute-job' |
|
// git路径 |
|
GIT_URL = 'http://git.gz.internal.jumaiyx.cn/job/room-server-clear.git' |
|
// 分支 |
|
GIT_BRANCH = '*/master' |
|
// kubectl执行文件 |
|
K8S_FILE = 'job.yaml' |
|
// k8s deployment名称,对应K8S_FILE里面Deployment的name |
|
K8S_DEPLOYMENT = 'room-hot-compute-job' |
|
} |
|
|
|
stages { |
|
stage('git代码拉取') { |
|
steps { |
|
checkout([$class: 'GitSCM', branches: [[name: "${env.GIT_BRANCH}"]], extensions: [], userRemoteConfigs: [[url: "${env.GIT_URL}"]]]) |
|
echo 'git代码拉取 成功' |
|
} |
|
} |
|
stage('docker镜像打包') { |
|
steps { |
|
echo "镜像版本:${env.BUILD_ID}" |
|
buildService("${env.SERVER_NAME}") |
|
echo 'docker镜像打包' |
|
} |
|
} |
|
stage('传入k8s-master') { |
|
steps { |
|
sshPublisher(publishers: [sshPublisherDesc(configName: 'k8s', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: "${env.K8S_FILE}")], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)]) |
|
echo '将yaml传入k8s-master' |
|
} |
|
} |
|
stage('部署服务') { |
|
steps { |
|
sh "ssh root@192.168.1.156 kubectl apply -f /usr/local/k8s/${env.K8S_FILE}" |
|
echo '部署服务' |
|
//sh '''if if (( ${env.BUILD_ID} == 1 )) |
|
//then |
|
// ssh root@192.168.1.156 kubectl apply -f /usr/local/k8s/${env.K8S_FILE} |
|
// echo '部署服务' |
|
//fi''' |
|
} |
|
} |
|
} |
|
}
|
|
|