kubesphere Maven + JDK17 安装
需求
目前项目使用的是jdk17,想使用kubesphere devops
查看官方文档
查看官网文档后,发现需要自定义Jenkins Agent
坑点:
找到jenkins-casc-config
配置后,改动用户文件才有效
加完之后可以运行官方的流水线测试一下,我的是3.3版本,默认就有jdk11
pipeline{
agent {
node {
label 'maven && jdk11'
}
}
stages {
stage('Print Maven and JDK version') {
steps {
container('maven') {
sh '''
mvn -v
java -version
'''
}
}
}
}
}
需要注意的是这里使用的label 'maven && jdk11'
去寻找容器打包的,这个应该是通过jdk11
找到这个镜像的
安装maven+jdk17环境
参照官方文档,找到对应位置后加入如下配置(自己选择加入就行了,这里有4个)
- name: "mavenjdk11"
label: "jdk11 maven java"
inheritFrom: "maven"
containers:
- name: "maven"
image: "registry.cn-beijing.aliyuncs.com/kubesphereio/builder-maven:v3.2.1-jdk11"
- name: "mymavenjdk11"
label: "mavenjdk11"
inheritFrom: "maven"
containers:
- name: "maven"
image: "registry.cn-beijing.aliyuncs.com/kubesphereio/builder-maven:v3.2.1-jdk11"
- name: "mavenjdk17"
label: "jdk17 maven java"
inheritFrom: "maven"
containers:
- name: "maven"
image: "lyaprotect/maven3.6.3-openjdk-17-graphviz:master-latest"
- name: "mymavenjdk17"
label: "mavenjdk17"
inheritFrom: "maven"
containers:
- name: "maven"
image: "lyaprotect/maven3.6.3-openjdk-17-graphviz:master-latest"
lyaprotect/maven3.6.3-openjdk-17-graphviz:master-latest
这个镜像是我在dockerhub
随便找的一个。
加完等该1-2分钟就行了,可以看到如下效果
后面maven打包时发现无法使用自己的maven仓库,镜像文件发现是没有去加载默认的settings文件,通过在dockerhub 查看镜像lyaprotect/maven3.6.3-openjdk-17-graphviz:master-latest
的打包过程,找到配置文件地址,替换就行了
- name: "mavenjdk11"
label: "jdk11 maven java"
inheritFrom: "maven"
containers:
- name: "maven"
image: "registry.cn-beijing.aliyuncs.com/kubesphereio/builder-maven:v3.2.1-jdk11"
- name: "mymavenjdk11"
label: "mavenjdk11"
inheritFrom: "maven"
containers:
- name: "maven"
image: "registry.cn-beijing.aliyuncs.com/kubesphereio/builder-maven:v3.2.1-jdk11"
- name: "mavenjdk17"
label: "jdk17 maven java"
inheritFrom: "maven"
containers:
- name: "maven"
image: "lyaprotect/maven3.6.3-openjdk-17-graphviz:master-latest"
yaml: |
spec:
containers:
- name: "maven"
volumeMounts:
- name: config-volume
mountPath: /usr/share/maven/conf/settings.xml
subPath: settings.xml
volumes:
- name: config-volume
configMap:
name: ks-devops-agent
items:
- key: MavenSetting
path: settings.xml
- name: "mymavenjdk17"
label: "mavenjdk17"
inheritFrom: "maven"
containers:
- name: "maven"
image: "lyaprotect/maven3.6.3-openjdk-17-graphviz:master-latest"
yaml: |
spec:
containers:
- name: "maven"
volumeMounts:
- name: config-volume
mountPath: /usr/share/maven/conf/settings.xml
subPath: settings.xml
volumes:
- name: config-volume
configMap:
name: ks-devops-agent
items:
- key: MavenSetting
path: settings.xml
只需要jdk17+maven打包用这个就行了
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZAue0U4c-1668352879704)(
)]
- name: "mymavenjdk17"
label: "mavenjdk17"
inheritFrom: "maven"
containers:
- name: "maven"
image: "lyaprotect/maven3.6.3-openjdk-17-graphviz:master-latest"
yaml: |
spec:
containers:
- name: "maven"
volumeMounts:
- name: config-volume
mountPath: /usr/share/maven/conf/settings.xml
subPath: settings.xml
volumes:
- name: config-volume
configMap:
name: ks-devops-agent
items:
- key: MavenSetting
path: settings.xml
测试流水线
可以使用以下流水线测试版本信息等
pipeline {
agent {
node {
label 'mavenjdk17'
}
}
stages {
stage('Print Maven and JDK version') {
agent none
steps {
container('maven') {
sh ''' java -version
mvn -v
cd /opt
ls -a
cd /usr/share/maven
ls -a
cd conf
ls -a
pwd
cat settings.xml'''
}
}
}
}
}