From 3e36a74daafdfa4dbb9fb4386d101d4a957c4abf Mon Sep 17 00:00:00 2001 From: newrain001 Date: Wed, 20 Dec 2023 20:39:17 +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 | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4ccfaf3..1df0576 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,14 +1,7 @@ -def KUBERNETES_NAME = "kubernetes" -def DOCKER_REPOSITORY_CREDENTIAL_ID = "ea3d4aae-783b-460f-9cd0-931c53c021db" -def HARBOR_HOST = "http://192.168.75.149:30002" -def NAMESPACE_NAME = "library" -def REPOSITORY_NAME = "my-web-app" -def TAG = "v1.0" - pipeline { agent { kubernetes { - cloud "${KUBERNETES_NAME}" + cloud "${env.KUBERNETES_NAME}" yaml """ apiVersion: v1 kind: Pod @@ -40,15 +33,23 @@ spec: """ } } + environment { + KUBERNETES_NAME = "kubernetes" + DOCKER_REPOSITORY_CREDENTIAL_ID = "ea3d4aae-783b-460f-9cd0-931c53c021db" + HARBOR_HOST = "http://192.168.75.149:30002" + NAMESPACE_NAME = "library" + REPOSITORY_NAME = "my-web-app" + TAG = "v1.0" + } stages { stage('构建镜像') { steps { - withCredentials([usernamePassword(credentialsId: '${DOCKER_REPOSITORY_CREDENTIAL_ID}', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) { + withCredentials([usernamePassword(credentialsId: env.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} + docker build -t ${env.HARBOR_HOST}/${env.NAMESPACE_NAME}/${env.REPOSITORY_NAME}:${env.TAG} . + docker login ${env.HARBOR_HOST} --username ${env.USERNAME} --password ${env.PASSWORD} + docker push ${env.HARBOR_HOST}/${env.NAMESPACE_NAME}/${env.REPOSITORY_NAME}:${env.TAG} """ } }