From 491c65f8db001e3c6ae79a1a7a8b68b5d8169106 Mon Sep 17 00:00:00 2001 From: newrain001 Date: Wed, 20 Dec 2023 20:37:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'Jenkinsfile'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 60 +++++++++++------------------------------------------ 1 file changed, 12 insertions(+), 48 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5f34bf9..4ccfaf3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,13 +9,6 @@ pipeline { agent { kubernetes { cloud "${KUBERNETES_NAME}" - // 增加超时时间为60分钟 - containerTemplate { - name 'docker' - image 'docker:19.03.15-git' - tty true - command 'cat' - } yaml """ apiVersion: v1 kind: Pod @@ -29,33 +22,18 @@ spec: - mountPath: "/etc/localtime" name: "volume-2" readOnly: false - - name: kubectl - image: kubersphere/kubectl:v1.22.0 - imagePullPolicy: IfNotPresent + - name: docker + image: docker:19.03.15-git + command: ['cat'] tty: true volumeMounts: - - mountPath: "/etc/localtime" - name: "volume-2" - readOnly: false - mountPath: "/var/run/docker.sock" name: "volume-docker" readOnly: false - - mountPath: "/.kube/config" - subPath: config - name: "kubeconfig" - readOnly: false volumes: - - name: volume-maven-repo - emptyDir: {} - name: volume-2 hostPath: path: "/usr/share/zoneinfo/Asia/Shanghai" - - name: kubeconfig - secret: - secretName: kubeconfig - items: - - key: config - path: config - name: volume-docker hostPath: path: "/var/run/docker.sock" @@ -63,32 +41,18 @@ spec: } } stages { - stage('Check Kubernetes ENV') { - steps { - container(name: 'kubectl', shell: 'echo') { - sh 'kubectl get pod -A' - } - - } - } - stage('构建镜像及检查kubernetes环境') { - parallel { - stage('构建镜像') { - steps { - withCredentials([usernamePassword(credentialsId: '${DOCKER_REPOSITORY_CREDENTIAL_ID}', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) { - container(name: 'docker', shell: 'echo') { - sh """ - docker build -t ${HARBOR_HOST}/${NAMESPACE_NAME}/${REPOSITORY_NAME}:${TAG} . - docker login ${HARBOR_HOST} --username=${USERNAME} --password=${PASSWORD} - docker push ${HARBOR_HOST}/${NAMESPACE_NAME}/${REPOSITORY_NAME}:${TAG} - """ - } - } + stage('构建镜像') { + steps { + withCredentials([usernamePassword(credentialsId: '${DOCKER_REPOSITORY_CREDENTIAL_ID}', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) { + container('docker') { + sh """ + docker build -t ${HARBOR_HOST}/${NAMESPACE_NAME}/${REPOSITORY_NAME}:${TAG} . + docker login ${HARBOR_HOST} --username ${USERNAME} --password ${PASSWORD} + docker push ${HARBOR_HOST}/${NAMESPACE_NAME}/${REPOSITORY_NAME}:${TAG} + """ } } } } - - } }