kubesphere安装Maven+JDK17 流水线打包

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'''
        }

      }
    }

  }
}
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值