更新 'Jenkinsfile'

main
newrain001 9 months ago
parent 9b7009c11f
commit 5a4884ff04
  1. 78
      Jenkinsfile

78
Jenkinsfile vendored

@ -4,19 +4,20 @@ def HARBOR_HOST = "http://192.168.75.149:30002"
def NAMESPACE_NAME = "library" def NAMESPACE_NAME = "library"
def REPOSITORY_NAME = "my-web-app" def REPOSITORY_NAME = "my-web-app"
def TAG = "v1.0" def TAG = "v1.0"
pipeline { pipeline {
agent { agent {
kubernetes{ kubernetes {
cloud "${KUBERNETES_NAME}" cloud "${KUBERNETES_NAME}"
slaveConnectTimeout 1200 slaveConnectTimeout 1200
yaml ''' yaml """
apiVersion: v1 apiVersion: v1
kind: Pod kind: Pod
spec: spec:
containers: containers:
- name: jnlp - name: jnlp
image: jenkins/inbound-agent:3107.v665000b_51092-15 image: jenkins/inbound-agent:3107.v665000b_51092-15
args: [\'$(JENKINS_SECRET)\', \'$(JENKINS_NAME)\'] args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)']
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
volumeMounts: volumeMounts:
- mountPath: "/etc/localtime" - mountPath: "/etc/localtime"
@ -30,7 +31,7 @@ spec:
- mountPath: "/etc/localtime" - mountPath: "/etc/localtime"
name: "volume-2" name: "volume-2"
readOnly: false readOnly: false
- mountPath: "/var/run/docker.sock" - mountPath: "/var/run/docker.sock"
name: "volume-docker" name: "volume-docker"
readOnly: false readOnly: false
- mountPath: "/etc/hosts" - mountPath: "/etc/hosts"
@ -69,45 +70,42 @@ spec:
- name: volume-hosts - name: volume-hosts
hostPath: hostPath:
path: /etc/hosts path: /etc/hosts
"""
}
'''
} }
} stages {
stages {
stage('Check Kubernetes ENV') { stage('Check Kubernetes ENV') {
steps { steps {
container(name: 'kubectl', shell: 'echo') { container(name: 'kubectl', shell: 'sh') {
sh 'kubectl get pod -A' sh 'kubectl get pod -A'
}
} }
}
} }
stage('构建镜像及检查kubernetes环境') { stage('构建镜像及检查kubernetes环境') {
parallel { parallel {
stage('构建镜像') { stage('构建镜像') {
steps { steps {
withCredentials([usernamePassword(credentialsId: '${DOCKER_REPOSITORY_CREDENTIAL_ID}', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) { withCredentials([usernamePassword(credentialsId: '${DOCKER_REPOSITORY_CREDENTIAL_ID}', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
container(name: 'docker', shell: 'echo') { container(name: 'docker', shell: 'sh') {
sh """ sh """
docker build -t ${HARBOR_HOST}/${NAMESPACE_NAME}/${REPOSITORY_NAME}:${TAG} . docker build -t ${HARBOR_HOST}/${NAMESPACE_NAME}/${REPOSITORY_NAME}:${TAG} .
docker login ${HARBOR_HOST} --username=${USERNAME} --password=${PASSWORD} docker login ${HARBOR_HOST} --username=${USERNAME} --password=${PASSWORD}
docker push ${HARBOR_HOST}/${NAMESPACE_NAME}/${REPOSITORY_NAME}:${TAG} 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'
}
}
}
}
} }

Loading…
Cancel
Save