1

We're trying to cache Maven artifacts across Jenkins pipeline runs so we don't have to re-download them with each run. We are performing runs declaratively in the JenkinsFile and the pipelines are being managed by kubernetes, basically this question but with Kubernetes. I suppose I will have to persist the .m2 directory with PV/PVC but i'm not sure if this is currently possible declaratively, would that be the best approach or is there an alternative solution for keeping maven dependencies available for each run?

JenkinsFile:

pipeline {

agent {
    kubernetes {
        yamlFile 'ci-cd/BuildPod.yaml'
    }
}
...

BuildPod:

apiVersion: v1
kind: Pod
metadata:
  namespace: jenkins
  labels:
    jenkins/label: 'api-slave'
spec:
  containers:
    - name: jnlp
    - name: mavenenv
      image: maven:3.6.2
      command:
        - bash
...
  • Setting up a mirroring repository locally is not an option? – Thorbjørn Ravn Andersen Jun 14 '23 at 06:23
  • Yes a mirroring repository (usually using a repository manager like Nexus, Artifactory or alike)... you could also take a look into https://maven.apache.org/extensions/maven-build-cache-extension/ (Ah no you can not use that because your Maven version is too old)... Upgrade to most recent versions 3.8.X or 3.9.X ... also an option might be https://plugins.jenkins.io/jobcacher/ – khmarbaise Jun 14 '23 at 06:39

0 Answers0