| I have this feature working in a scripted pipeline but when I tried to use it in a declarative pipeline it would never create the workspace volume as a persistent volume claim, it would only mount "emptyDir" volumes for the workspace. The declarative pipeline I'm using is
pipeline {
agent {
kubernetes {
yamlFile 'jenkins/pv-pod.yaml'
defaultContainer 'tree'
}
}
options {
podTemplate(workspaceVolume: persistentVolumeClaimWorkspaceVolume(claimName: 'workspace', readOnly: false))
}
stages {
stage('read workspace') {
steps {
echo 'current env'
sh 'env'
sh '/usr/bin/tree'
echo 'previous env'
sh 'cat old-env.txt || true'
sh 'env > old-env.txt'
}
}
}
}
With a 'pv-pod.yaml' file with these contents
apiVersion: v1
kind: Pod
spec:
containers:
- name: tree
image: iankoulski/tree
command:
- /bin/cat
tty: true
This is in kubenernetes-plugin version 1.25.3. |