How to define workspace volume for jenkins pipeline declarative
Try something like
podTemplate( containers: [ containerTemplate(name: 'tree', image: 'iankoulski/tree', ttyEnabled: true, command: 'cat') ], workspaceVolume: persistentVolumeClaimWorkspaceVolume(claimName: 'workspace', readOnly: false),) { node(POD_LABEL) { stage('read workspace') { checkout scm container('tree') { sh 'env' sh 'tree' sh 'test -f old-env.txt && cat old-env.txt' sh 'env > old-env.txt' } } }}
Here is an example for declarative pipeline:
pipeline {agent { kubernetes { yamlFile 'jenkins/pv-pod.yaml' workspaceVolume persistentVolumeClaimWorkspaceVolume(claimName: 'workspace', readOnly: false) }}
If you post your jenkins deployment then I might help in that.
Mean while you can visit this yaml that I used and worked very well for me.
apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: jenkinsspec: replicas: 1 template: metadata: labels: app: jenkins spec: containers: - name: jenkins image: jenkins:2.32.2 ports: - containerPort: 8080 volumeMounts: - name: jenkins-home mountPath: /var/jenkins_home volumes: - name: jenkins-home emptyDir: {}