# About JENKINS\_AGENT\_WORKDIR persistence in jenkins/inbound-agent

**URL:** <https://community.jenkins.io/t/about-jenkins-agent-workdir-persistence-in-jenkins-inbound-agent/27874>\
**Category:** Using Jenkins\
**Created:** [March 7, 2025, 1:33am UTC](https://community.jenkins.io/t/about-jenkins-agent-workdir-persistence-in-jenkins-inbound-agent/27874 "2025-03-07T01:33:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cscowx](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@cscowx](https://community.jenkins.io/u/cscowx)\
**Post date:** [March 7, 2025, 1:33am UTC](https://community.jenkins.io/t/about-jenkins-agent-workdir-persistence-in-jenkins-inbound-agent/27874/1 "2025-03-07T01:33:40Z")

</div>

Hello, everybody.

Thanks for reading my post.

I used kubernetes{} plugin to dynamically generate jenkins agent pod and complete a series of tasks

What happens is that when Pod starts, it will generate caches, workspace, remoting, and so on in /home/jenkins/agent/. I now want to persist this directory to an NFS volume. When I mount the NFS volume to the /home/jencs/agent directory, the directory ends up empty and subsequent stage tasks fail.

I observed later that when Pod started, it generated a number of directories and files in /home/jenkins/agent, and /home/jenkins/agent was overwritten when I mounted the NFS volume there

I want to mount the NFS volume into /home/jenkins/agent directory when pod starts so that all the generated files end up in the NFS volume. Is there anything you can recommend

I used an NFS volume because I wanted to share the caches and workspace directories in /home/jenkins/agent so I could use them later

The pipeline script is as follows:

```auto
pipeline {
    agent {
        kubernetes {
          cloud 'k8s'
          defaultContainer 'jenkins-inbound-agent-maven-latest-jdk21'
          retries 2
          yaml """
---
apiVersion: v1
kind: Pod
metadata:
  labels:
    jenkins-slave-pod-name: ${JENKINS_SLAVE_POD_LABEL}
    jenkins-job-info: ${env.JOB_NAME}.${env.BUILD_NUMBER}
  namespace: devops
spec:
  securityContext:
    runAsUser: 1000
    runAsGroup: 1000
    fsGroup: 1000
  hostAliases:
    - ip: "192.168.110.208"
      hostnames:
        - "reg.zxactions.com"
  containers:
  - name: jenkins-inbound-agent-maven-latest-jdk21
    image: jenkins/inbound-agent:latest-jdk21
    imagePullPolicy: Always
    ttyEnabled: false
    command:
      - sleep
    args:
      - infinity
    volumeMounts:
      - name: maven-cache
        mountPath: /home/jenkins/.m2
        readOnly: false
      - name: agent-dir-path
        mountPath: /home/jenkins/agent
        readOnly: false
  volumes:
    - name: maven-cache
      persistentVolumeClaim:
        claimName: nfs-pvc-local-claim-01
    - name: agent-dir-path
      nfs:
        server: 192.168.110.220
        path: /nfs-data/jenkins-slave-agent/
        options: "nfsvers=4.2,rsize=1048576,wsize=1048576,noatime,nodiratime,tcp,hard,intr"
          """
        }
    }

    stages {
        stage('拉取代码') {
          steps {
            retry(count: 2, conditions: [kubernetesAgent(), nonresumable()]) {
              container('jenkins-inbound-agent-maven-latest-jdk21') {
                sh '''
                echo 'hello' && hostname && pwd && ls $(pwd) && ls /home/jenkins/agent/workspace
                '''
              }
            }
          }  
        }
    }
}

```
