• Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • kubernetes-plugin
    • None
    • Jenkins 2.32.1
      pipeline 2.4
      kubernetes-plugin 0.10

      If pipeline has dir wrapper, i.e.

      podTemplate(...) {
        node('pod') {
          container('mycontainer') {
            dir('my/dir/path') {
              sh 'ls -l'
            }
          }
        }
      }
      

      shell step is still executed in the context of workspace root.
      Same pipeline works as expected (within directory path specified by dir step) outside of kubernetes pod.

          [JENKINS-40925] "dir" context is not honored by "sh" step

          +1 to this issue, observing the same

          Sergey Kulanov added a comment - +1 to this issue, observing the same

          Sergey Kulanov added a comment - Not an expert, but from the fast look, it seems that the issue is somewhere here https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecorator.java#L123-L129

          btw, you can try as workaround to run

          podTemplate(...) {
            node('pod') {
               dir('my/dir/path') { 
                 container('mycontainer') {
                   sh 'ls -l'
                 }
               }
            }
          }
          

          but definitely this breaks current user experience (existing pipeline scripts), probably this should be documented as well, like container step supports only sh step, but not sure, we need to see some comment from csanchez

          Sergey Kulanov added a comment - btw, you can try as workaround to run podTemplate(...) { node( 'pod' ) { dir( 'my/dir/path' ) { container( 'mycontainer' ) { sh 'ls -l' } } } } but definitely this breaks current user experience (existing pipeline scripts), probably this should be documented as well, like container step supports only sh step , but not sure, we need to see some comment from csanchez

          I don't think this is possible in pipeline yet, based on JENKINS-33510

          Carlos Sanchez added a comment - I don't think this is possible in pipeline yet, based on JENKINS-33510

          Roman Safronov added a comment - - edited

          I'm looking at the code of org.jenkinsci.plugins.workflow.steps.PushdStep.Execution#start and org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator#decorate and it look like context is just ignored by LauncherDecorator.

          I want to try to fix this issue.
          csanchez can you please add at least basic steps on how to configure integration test environment for this plugin?

          Roman Safronov added a comment - - edited I'm looking at the code of org.jenkinsci.plugins.workflow.steps.PushdStep.Execution#start and org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator#decorate and it look like context is just ignored by LauncherDecorator. I want to try to fix this issue. csanchez can you please add at least basic steps on how to configure integration test environment for this plugin?

          OK. It runs out of the box with minikube.

          Roman Safronov added a comment - OK. It runs out of the box with minikube.

          Roman Safronov added a comment - - edited

          So, it looks like hudson.Launcher.ProcStarter#pwd() provides correct path including "dir" context.
          It is available in org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator.

          Is there a reason not to use it?
          If not I can make PR with change and test.

          Roman Safronov added a comment - - edited So, it looks like hudson.Launcher.ProcStarter#pwd() provides correct path including "dir" context. It is available in org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator. Is there a reason not to use it? If not I can make PR with change and test.

          Roman Safronov added a comment - PR#146

          J Knurek added a comment -

          should this already be closed if v0.11 (the current released version) doesn't contain the fix? Isn't Resolved the proper status? 

          or in other words, can we get 0.12 built

          J Knurek added a comment - should this already be closed if v0.11 (the current released version) doesn't contain the fix? Isn't Resolved the proper status?  or in other words, can we get 0.12 built

            csanchez Carlos Sanchez
            electroma Roman Safronov
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: