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

`dir` does not change working directory for contained steps

    • docker-workflow 1.19

      It's said here, https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-dir-code-change-current-directory

      Change current directory. Any step inside the dir block will use this directory as current and any relative path will use it as base path.

      However, I can't seem to get it work. I use declarative syntax with a very basic Jenkinsfile

       

      pipeline {
          agent none
      
          stages {
      
              stage('Change working directory...') {
                  agent { docker 'my-image' }
      
                  steps {
                      dir('new-dir') {
                          sh 'pwd'
                      }
                  }
              }
          }
      }

      What it does is simply create a new folder called "new-dir" in the current working directory and then the pwd prints out the current working directory instead of navigating into the "new-dir".

      Am I misusing this step because I can't find many examples online. I have found some relevant issues here, but none of them is of any help to me.

       

          [JENKINS-46636] `dir` does not change working directory for contained steps

          Michael Wu created issue -
          Michael Wu made changes -
          Labels Original: directory jenkins pipeline New: directory docker jenkins pipeline
          Michael Wu made changes -
          Resolution New: Done [ 10000 ]
          Status Original: Open [ 1 ] New: Closed [ 6 ]
          Dave P made changes -
          Resolution Original: Done [ 10000 ]
          Status Original: Closed [ 6 ] New: Reopened [ 4 ]
          Yuriy Burtsev made changes -
          Assignee New: Oleg Nenashev [ oleg_nenashev ]
          Michael Slattery made changes -
          Component/s New: docker-workflow-plugin [ 20625 ]
          Andrew Bayer made changes -
          Component/s Original: pipeline [ 21692 ]
          Andrew Bayer made changes -
          Labels Original: directory docker jenkins pipeline New: directory docker jenkins pipeline triaged-2018-11
          Oleg Nenashev made changes -
          Assignee Original: Oleg Nenashev [ oleg_nenashev ]
          Devin Nusbaum made changes -
          Released As New: docker-workflow 1.19
          Resolution New: Fixed [ 1 ]
          Status Original: Reopened [ 4 ] New: Resolved [ 5 ]

            Unassigned Unassigned
            michaelonline Michael Wu
            Votes:
            18 Vote for this issue
            Watchers:
            23 Start watching this issue

              Created:
              Updated:
              Resolved: