1、jenkins插件安装:
CloudBees Docker Hub/Registry Notification 等。
2、jenkins全局工具配置
3、凭证配置,需配置gitlab、harbor的账户凭证
4、harbor中创建xxl-job
5、gitlab中创建Dockerfile和deploy.yml
dockerfile
FROM primetoninc/jdk:1.8
run mkdir -p /opt/admin
COPY xxl-job-admin/target/xxl-job-admin-2.3.0.jar /opt/admin
WORKDIR /opt/admin
CMD java -jar xxl-job-admin-2.3.0.jar
deploy.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: xxl-admin
spec:
replicas: 1
selector:
matchLabels:
app: xxl-job-admin
template:
metadata:
labels:
app: xxl-job-admin
spec:
containers:
- name: xxl-job-admin
imagePullPolicy: IfNotPresent
image: "harbor.zyc.cmiot/xxl-job/xxl-job-admin:2.3.0"
nodeName: 10.xx.xx.xx
6、创建jenkins流水线
pipeline
pipeline{
agent any
tools {
maven 'my-maven'
jdk 'my-jdk'
}
environment {
DOCKER_CERT_PATH = credentials('b6df91be-f296-48c9-9e3e-f6d96e2877d2')
}
stages{
stage('git clone'){
steps{
git branch: 'main', credentialsId: '3b0fa744-7bd1-4e99-903f-56d12339d99d', url: 'http://10.xx.xx.105:8011/root/xxl-job.git'
}
}
stage('build'){
steps{
sh '''
mvn clean package
docker build -t harbor.zyc.cmiot/xxl-job/xxl-job-admin:2.3.0 .
'''
}
}
stage('push image to harbor'){
steps{
sh '''
docker push harbor.zyc.cmiot/xxl-job/xxl-job-admin:2.3.0
'''
}
}
stage('deploy'){
steps{
sh '/opt/kube/bin/kubectl apply -f deploy.yml'
}
}
}
}
说明:docker将自动使用DOCKER_CERT_PATH来登录harbor,无需在进行docker login登录
7、运行流水线结果
(1)流水线阶段视图
(2)harbor仓库
(3)k8s pod
参考
docker流水线凭证:https://plugins.jenkins.io/docker-commons/