|
|
|
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}"
|
|
|
|
slaveConnectTimeout 1200
|
|
|
|
yaml '''
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Pod
|
|
|
|
spec:
|
|
|
|
containers:
|
|
|
|
- name: jnlp
|
|
|
|
image: jenkins/inbound-agent:3107.v665000b_51092-15
|
|
|
|
args: [\'$(JENKINS_SECRET)\', \'$(JENKINS_NAME)\']
|
|
|
|
imagePullPolicy: IfNotPresent
|
|
|
|
volumeMounts:
|
|
|
|
- mountPath: "/etc/localtime"
|
|
|
|
name: "volume-2"
|
|
|
|
readOnly: false
|
|
|
|
- name: docker
|
|
|
|
image: docker:19.03.15-git
|
|
|
|
imagePullPolicy: IfNotPresent
|
|
|
|
tty: true
|
|
|
|
volumeMounts:
|
|
|
|
- mountPath: "/etc/localtime"
|
|
|
|
name: "volume-2"
|
|
|
|
readOnly: false
|
|
|
|
- mountPath: "/var/run/docker.sock"
|
|
|
|
name: "volume-docker"
|
|
|
|
readOnly: false
|
|
|
|
- mountPath: "/etc/hosts"
|
|
|
|
name: "volume-hosts"
|
|
|
|
readOnly: false
|
|
|
|
- name: kubectl
|
|
|
|
image: bitnami/kubectl:1.22.0
|
|
|
|
imagePullPolicy: IfNotPresent
|
|
|
|
tty: true
|
|
|
|
args: ["get","pod","-A"]
|
|
|
|
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"
|
|
|
|
- name: volume-hosts
|
|
|
|
hostPath:
|
|
|
|
path: /etc/hosts
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('Check Kubernetes ENV') {
|
|
|
|
steps {
|
|
|
|
container(name: 'kubectl', shell: 'echo') {
|
|
|
|
sh 'kubectl get pod -A'
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Deploy Image to Kubernetes') {
|
|
|
|
steps {
|
|
|
|
container(name: 'kubectl', shell: 'echo') {
|
|
|
|
sh 'sleep 10'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Test Service') {
|
|
|
|
steps {
|
|
|
|
sh 'sleep 10'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Send Email to Admin') {
|
|
|
|
steps {
|
|
|
|
sh 'sleep 10'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|