Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-59160

Cannot Override workingDir for jnlp container

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: kubernetes-plugin
    • Labels:
      None
    • Environment:
      Jenkins: 2.176.2
      Jenkins Kubernetes Plugin: 1.18.3
      Kubernetes: v1.13.9
      Cluster OS: Amazon Linux, 64-Bit
    • Similar Issues:

      Description

      With version 1.18.3 of the Jenkins Kubernetes Plugin, I am not able to override the default workingDir for the jnlp container. Here's the pod template I am using: 

          agent {
              kubernetes {
                  // Using a dynamic pod n ame because static labels are known to cause pod creation errors.
                  label "mypod-${UUID.randomUUID().toString()}"
                  defaultContainer "maven"
                  yaml """
      apiVersion: v1
      kind: Pod
      spec:
        containers:
        - name: jnlp
          image: jenkins/jnlp-slave:alpine
          args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)']
          workingDir: /home/jenkins/agent2
        - name: maven
          image: maven:3.5.3-jdk-8
          command:
          - cat
          tty: true
          workingDir: /home/jenkins/agent2
      """
              }
          }
      

      Job errors as (I have added -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true) 

      sh: 1: cd: can't cd to /home/jenkins/agent/workspace/Pipeline_With_WorkingDir
      sh: 1: cannot create /home/jenkins/agent/workspace/Pipeline_With_WorkingDir@tmp/durable-cf37f355/jenkins-log.txt: Directory nonexistent
      sh: 1: cannot create /home/jenkins/agent/workspace/Pipeline_With_WorkingDir@tmp/durable-cf37f355/jenkins-result.txt.tmp: Directory nonexistent
      mv: cannot stat '/home/jenkins/agent/workspace/Pipeline_With_WorkingDir@tmp/durable-cf37f355/jenkins-result.txt.tmp': No such file or directory
      process apparently never started in /home/jenkins/agent/workspace/Pipeline_With_WorkingDir@tmp/durable-cf37f355
      

      It appears that the workingDir on our declared jnlp container is not being respected. If I set workingDir to /home/jenkins/agent everything works as expected.  

      We have a large number of existing jobs that depend on the workingDir being set to /home/jenkins. The change to default it to /home/jenkins/agent in v1.18.0 (https://github.com/jenkinsci/kubernetes-plugin/releases/tag/kubernetes-1.18.0) caused a lot of our jobs to start failing due to them unfortunately having references to /home/jenkins spread throughout their build & test logic. We are attempting to force the default workingDir back to /home/jenkins until we can update all our existing references to it. 

        Attachments

          Activity

          mikenau_intuit Mike Nau created issue -
          mikenau_intuit Mike Nau made changes -
          Field Original Value New Value
          Description With version 1.18.3 of the Jenkins Kubernetes Plugin, I am not able to override the default workingDir for the jnlp container. Here's the pod template I am using:

           
          {code:java}
              agent {
                  kubernetes {
                      // Using a dynamic pod n ame because static labels are known to cause pod creation errors.
                      label "mypod-${UUID.randomUUID().toString()}"
                      defaultContainer "maven"
                      yaml """
          apiVersion: v1
          kind: Pod
          spec:
            containers:
            - name: jnlp
              image: jenkins/jnlp-slave:alpine
              args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)']
              workingDir: /home/jenkins/agent2
            - name: maven
              image: maven:3.5.3-jdk-8
              command:
              - cat
              tty: true
              workingDir: /home/jenkins/agent2
          """
                  }
              }
          {code}
          Job errors as (I have added -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true)

           

           
          {code:java}
          sh: 1: cd: can't cd to /home/jenkins/agent/workspace/Pipeline_With_WorkingDir
          sh: 1: cannot create /home/jenkins/agent/workspace/Pipeline_With_WorkingDir@tmp/durable-cf37f355/jenkins-log.txt: Directory nonexistent
          sh: 1: cannot create /home/jenkins/agent/workspace/Pipeline_With_WorkingDir@tmp/durable-cf37f355/jenkins-result.txt.tmp: Directory nonexistent
          mv: cannot stat '/home/jenkins/agent/workspace/Pipeline_With_WorkingDir@tmp/durable-cf37f355/jenkins-result.txt.tmp': No such file or directory
          process apparently never started in /home/jenkins/agent/workspace/Pipeline_With_WorkingDir@tmp/durable-cf37f355
          {code}
          It appears that the workingDir on our declared jnlp container is not being respected. If I set workingDir to /home/jenkins/agent everything works as expected. 

           

          We have a large number of existing jobs that depend on the workingDir being set to /home/jenkins. The change to default it to /home/jenkins/agent in v1.18.0 ([https://github.com/jenkinsci/kubernetes-plugin/releases/tag/kubernetes-1.18.0]) caused a lot of our jobs to start failing due to them unfortunately having references to /home/jenkins spread throughout their build & test logic. We are attempting to force the default workingDir back to /home/jenkins until we can update all our existing references to it. 
          With version 1.18.3 of the Jenkins Kubernetes Plugin, I am not able to override the default workingDir for the jnlp container. Here's the pod template I am using: 
          {code:java}
              agent {
                  kubernetes {
                      // Using a dynamic pod n ame because static labels are known to cause pod creation errors.
                      label "mypod-${UUID.randomUUID().toString()}"
                      defaultContainer "maven"
                      yaml """
          apiVersion: v1
          kind: Pod
          spec:
            containers:
            - name: jnlp
              image: jenkins/jnlp-slave:alpine
              args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)']
              workingDir: /home/jenkins/agent2
            - name: maven
              image: maven:3.5.3-jdk-8
              command:
              - cat
              tty: true
              workingDir: /home/jenkins/agent2
          """
                  }
              }
          {code}
          Job errors as (I have added -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true) 
          {code:java}
          sh: 1: cd: can't cd to /home/jenkins/agent/workspace/Pipeline_With_WorkingDir
          sh: 1: cannot create /home/jenkins/agent/workspace/Pipeline_With_WorkingDir@tmp/durable-cf37f355/jenkins-log.txt: Directory nonexistent
          sh: 1: cannot create /home/jenkins/agent/workspace/Pipeline_With_WorkingDir@tmp/durable-cf37f355/jenkins-result.txt.tmp: Directory nonexistent
          mv: cannot stat '/home/jenkins/agent/workspace/Pipeline_With_WorkingDir@tmp/durable-cf37f355/jenkins-result.txt.tmp': No such file or directory
          process apparently never started in /home/jenkins/agent/workspace/Pipeline_With_WorkingDir@tmp/durable-cf37f355
          {code}
          It appears that the workingDir on our declared jnlp container is not being respected. If I set workingDir to /home/jenkins/agent everything works as expected.  

          We have a large number of existing jobs that depend on the workingDir being set to /home/jenkins. The change to default it to /home/jenkins/agent in v1.18.0 ([https://github.com/jenkinsci/kubernetes-plugin/releases/tag/kubernetes-1.18.0]) caused a lot of our jobs to start failing due to them unfortunately having references to /home/jenkins spread throughout their build & test logic. We are attempting to force the default workingDir back to /home/jenkins until we can update all our existing references to it. 
          Hide
          pyieh Pierson Yieh added a comment -

          We also noticed that `workingDir` was only being ignored when being declared from a podTemplate / pipeline from a Jenkinsfile. Setting the working directory from pod templates saved on the Jenkins Master configuration page were being respected.

          Show
          pyieh Pierson Yieh added a comment - We also noticed that `workingDir` was only being ignored when being declared from a podTemplate / pipeline from a Jenkinsfile. Setting the working directory from pod templates saved on the Jenkins Master configuration page were being respected.
          Hide
          nito Nito Martinez added a comment - - edited

          I had the same problem and this works for me:

          Workaround:

          I was able to get this working by defining the HOME variable, in my particular case I set only the HOME variable for the helm container (the jnlp container had it already defined as HOME="/tmp")

          apiVersion: v1
          kind: Pod
          spec:
            containers:
            - name: jnlp
              image: "quay.io/openshift/origin-jenkins-agent-maven:4.5"
              env:
              - name: CONTAINER_HEAP_PERCENT
                value: "0.25"
              - name: GIT_COMMITTER_NAME
                value: "Jenkins"
              - name: GIT_COMMITTER_EMAIL
                value: "jenkins@jenkins.com"
              volumeMounts:
              - name: maven-cache
                mountPath: /home/jenkins/.m2/repository
              resources:
                limits:
                  memory: 512Mi
                requests:
                  memory: 512Mi
            - name: helm
              image: "lachlanevenson/k8s-helm:v2.16.7"
              command: ["cat"]
              tty: true
              env:
              - name: GIT_COMMITTER_NAME
                value: "Jenkins"
              - name: GIT_COMMITTER_EMAIL
                value: "jenkins@jenkins.com"
              - name: HOME
                value: "/tmp"
            volumes:
            - name: maven-cache
              persistentVolumeClaim:
                claimName: "maven-cache"
          
          Show
          nito Nito Martinez added a comment - - edited I had the same problem and this works for me: Workaround: I was able to get this working by defining the HOME variable, in my particular case I set only the HOME variable for the helm container (the jnlp container had it already defined as HOME="/tmp") apiVersion: v1 kind: Pod spec: containers: - name: jnlp image: "quay.io/openshift/origin-jenkins-agent-maven:4.5" env: - name: CONTAINER_HEAP_PERCENT value: "0.25" - name: GIT_COMMITTER_NAME value: "Jenkins" - name: GIT_COMMITTER_EMAIL value: "jenkins@jenkins.com" volumeMounts: - name: maven-cache mountPath: /home/jenkins/.m2/repository resources: limits: memory: 512Mi requests: memory: 512Mi - name: helm image: "lachlanevenson/k8s-helm:v2.16.7" command: ["cat"] tty: true env: - name: GIT_COMMITTER_NAME value: "Jenkins" - name: GIT_COMMITTER_EMAIL value: "jenkins@jenkins.com" - name: HOME value: "/tmp" volumes: - name: maven-cache persistentVolumeClaim: claimName: "maven-cache"
          Hide
          allan_burdajewicz Allan BURDAJEWICZ added a comment -

          > The change to default it to /home/jenkins/agent in v1.18.0 (https://github.com/jenkinsci/kubernetes-plugin/releases/tag/kubernetes-1.18.0) caused a lot of our jobs to start failing due to them unfortunately having references to /home/jenkins spread throughout their build & test logic. We are attempting to force the default workingDir back to /home/jenkins until we can update all our existing references to it.

          I believe this has been addressed by https://issues.jenkins-ci.org/browse/JENKINS-60977 (shipped in version 1.24.0). In that version, you should be able to use the old value.

          Show
          allan_burdajewicz Allan BURDAJEWICZ added a comment - > The change to default it to /home/jenkins/agent in v1.18.0 ( https://github.com/jenkinsci/kubernetes-plugin/releases/tag/kubernetes-1.18.0 ) caused a lot of our jobs to start failing due to them unfortunately having references to /home/jenkins spread throughout their build & test logic. We are attempting to force the default workingDir back to /home/jenkins until we can update all our existing references to it. I believe this has been addressed by https://issues.jenkins-ci.org/browse/JENKINS-60977 (shipped in version 1.24.0). In that version, you should be able to use the old value.

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            mikenau_intuit Mike Nau
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated: