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

"dir" context is not honored by "sh" step

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • kubernetes-plugin
    • None
    • Jenkins 2.32.1
      pipeline 2.4
      kubernetes-plugin 0.10

    Description

      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.

      Attachments

        Issue Links

          Activity

            electroma Roman Safronov created issue -
            electroma Roman Safronov made changes -
            Field Original Value New Value
            Description If pipeline has *dir* wrapper, i.e.
            {code}
            podTemplate(...) {
              node('pod') {
                container('mycontainer') {
                  dir('my/dir/path') {
                    sh 'ls -l'
                  }
                }
              }
            }
            {code}
            *shell* step is still executed in the context of workspace root.
            Same pipeline works as expected (within directory path specified by *dir* step)
            If pipeline has *dir* wrapper, i.e.
            {code}
            podTemplate(...) {
              node('pod') {
                container('mycontainer') {
                  dir('my/dir/path') {
                    sh 'ls -l'
                  }
                }
              }
            }
            {code}
            *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.

            +1 to this issue, observing the same

            skulanov Sergey Kulanov added a comment - +1 to this issue, observing the same
            skulanov 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

            skulanov 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

            csanchez Carlos Sanchez added a comment - I don't think this is possible in pipeline yet, based on JENKINS-33510
            csanchez Carlos Sanchez made changes -
            Link This issue is related to JENKINS-33510 [ JENKINS-33510 ]
            electroma 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?

            electroma 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.

            electroma Roman Safronov added a comment - OK. It runs out of the box with minikube.
            electroma 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.

            electroma 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.
            electroma Roman Safronov added a comment - PR#146
            csanchez Carlos Sanchez made changes -
            Resolution Fixed [ 1 ]
            Status Open [ 1 ] Closed [ 6 ]
            jknurek 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

            jknurek 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 made changes -
            Link This issue is duplicated by JENKINS-43188 [ JENKINS-43188 ]

            People

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

              Dates

                Created:
                Updated:
                Resolved: