PersistentVolumeClaim workspace for jenkins slave PersistentVolumeClaim workspace for jenkins slave kubernetes kubernetes

PersistentVolumeClaim workspace for jenkins slave


To help anyone who comes across this question much later like I have, there is property on kubernetes in the agent section, that defines how the workspace volume is handled. Jenkins will extend whatever your agent YAML file contains with a mount and volume for the workspace.

So to use an existing persistent volume claim, you would do:

pipeline {    agent {        kubernetes {            yaml podTemplate            workspaceVolume persistentVolumeClaimWorkspaceVolume(claimName: 'jenkins-slave-pvc', readOnly: false)        }    }...}

Depending on how your persistent volume is set up and what kind of parallel builds you support, you may want to go with dynamic persistent volume claims instead, so that each build agent gets it's own workspace volume. You can configure that functionality with:

pipeline {    agent {        kubernetes {            yaml podTemplate            workspaceVolume dynamicPVC(accessModes: 'ReadWriteOnce', requestsSize: "10Gi")        }    }...}