You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
k8s-test/Jenkinsfile

58 lines
1.8 KiB

pipeline {
environment {
DOCKER_REPOSITORY_CREDENTIAL_ID = "ea3d4aae-783b-460f-9cd0-931c53c021db"
HARBOR_HOST = "192.168.75.149:30002"
NAMESPACE_NAME = "library"
REPOSITORY_NAME = "my-web-app"
TAG = "v1.0"
}
agent {
kubernetes {
cloud "kubernetes"
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
command: ['cat']
tty: true
volumeMounts:
- mountPath: "/var/run/docker.sock"
name: "volume-docker"
readOnly: false
volumes:
- name: volume-2
hostPath:
path: "/usr/share/zoneinfo/Asia/Shanghai"
- name: volume-docker
hostPath:
path: "/var/run/docker.sock"
"""
}
}
stages {
stage('构建镜像') {
steps {
withCredentials([usernamePassword(credentialsId: env.DOCKER_REPOSITORY_CREDENTIAL_ID, passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
container('docker') {
sh """
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}
"""
}
}
}
}
}
}