diff --git a/Jenkinsfile b/Jenkinsfile index bceba06..ff0b2bf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,19 +4,20 @@ 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}" - slaveConnectTimeout 1200 - yaml ''' + agent { + kubernetes { + cloud "${KUBERNETES_NAME}" + slaveConnectTimeout 1200 + yaml """ apiVersion: v1 kind: Pod spec: containers: - name: jnlp image: jenkins/inbound-agent:3107.v665000b_51092-15 - args: [\'$(JENKINS_SECRET)\', \'$(JENKINS_NAME)\'] + args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)'] imagePullPolicy: IfNotPresent volumeMounts: - mountPath: "/etc/localtime" @@ -30,7 +31,7 @@ spec: - mountPath: "/etc/localtime" name: "volume-2" readOnly: false - - mountPath: "/var/run/docker.sock" + - mountPath: "/var/run/docker.sock" name: "volume-docker" readOnly: false - mountPath: "/etc/hosts" @@ -69,45 +70,42 @@ spec: - name: volume-hosts hostPath: path: /etc/hosts - - -''' +""" + } } - } - stages { + stages { stage('Check Kubernetes ENV') { - steps { - container(name: 'kubectl', shell: 'echo') { - sh 'kubectl get pod -A' + steps { + container(name: 'kubectl', shell: 'sh') { + 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('构建镜像及检查kubernetes环境') { + parallel { + stage('构建镜像') { + steps { + withCredentials([usernamePassword(credentialsId: '${DOCKER_REPOSITORY_CREDENTIAL_ID}', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) { + container(name: 'docker', shell: 'sh') { + 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('Check Kubernetes ENV') { - steps { - container(name: 'kubectl', shell: 'echo') { - sh 'kubectl get pod -A' - } - } - } -} + stage('Check Kubernetes ENV (Again)') { + steps { + container(name: 'kubectl', shell: 'sh') { + sh 'kubectl get pod -A' + } + } + } + } }