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

file permissions are lost after unstashing on windows node

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • Jenkins 2.140
      Pipeline 2.5

      Consider the following script:

      node( 'macos' ) {
        sh 'rm -rf *'
        sh 'echo "int main() { return 0; }" > test.cpp'
        sh 'mkdir bin && gcc test.cpp -o bin/test'
        sh "ls -l bin"
        stash name:'test', includes: "bin/*"
      }node( 'windows' ) {
          unstash 'test'
          stash name:'test2', includes: 'bin/*'
      }node( 'linux' ) {
        sh 'rm -rf *'
        unstash 'test2'
        sh "ls -l bin"
      }
      

      It produces the following output:

      Started by user Nenad Mikša
      Running in Durability level: PERFORMANCE_OPTIMIZED
      [Pipeline] node
      Running on macpro2 in /opt/jenkins/workspace/Test
      [Pipeline] {
      [Pipeline] sh
      [Test] Running shell script
      + rm -rf bin test.cpp
      [Pipeline] sh
      [Test] Running shell script
      + echo 'int main() { return 0; }'
      [Pipeline] sh
      [Test] Running shell script
      + mkdir bin
      + gcc test.cpp -o bin/test
      [Pipeline] sh
      [Test] Running shell script
      + ls -l bin
      total 16
      -rwxr-xr-x  1 pero  staff  4248 Aug 31 20:40 test
      [Pipeline] stash
      Stashed 1 file(s)
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] node
      Running on Jabba in C:\Jenkins\workspace\Test
      [Pipeline] {
      [Pipeline] unstash
      [Pipeline] stash
      Stashed 1 file(s)
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] node
      Running on blade in /opt/jenkins/root/workspace/Test
      [Pipeline] {
      [Pipeline] sh
      [Test] Running shell script
      + rm -rf test.sh
      [Pipeline] unstash
      [Pipeline] sh
      [Test] Running shell script
      + ls -l bin
      total 8
      -rw-r--r-- 1 jenkins users 4248 Aug 31 20:40 test
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

      So, after unstashing the unix binary on windows node and stashing it back, it loses its unix file permissions.

       

      Since windows does not have unix file permissions, I would expect that on windows would treat all files in 777 mode, especially after stashing back.

       

      In case if you are wondering why is this important to me, here is the explanation:

      I use Jenkins to build Conan packages of my software. The binaries are first built on various nodes for various platforms (windows, linux, macos, android and ios) and after binaries for every platform have been built successfully, they are all collected on first available node using the stash/unstash mechanism and there they are packaged and uploaded to Conan repository.

      Due to this issue this causes for binaries that are built on unix nodes lose their file permissions if they are packaged on windows node. A possible workaround would be to enforce packaging on unix node or to perform some partial packaging on nodes that have created the binaries. As these workarounds work for me, I've set priority of this issue as "minor".

          [JENKINS-53374] file permissions are lost after unstashing on windows node

          Mike Dahlke added a comment - - edited

          I am also affected by this issue, use case is:

          • repo is cloned on Windows
          • project is built
          • build/tests/scripts are stashed
          • files are unstashed on a Linux node
          • automation is executed via a script

          The last step fails because the scripts no longer have the execute bit set.

           

          Mike Dahlke added a comment - - edited I am also affected by this issue, use case is: repo is cloned on Windows project is built build/tests/scripts are stashed files are unstashed on a Linux node automation is executed via a script The last step fails because the scripts no longer have the execute bit set.  

          Quentin Nerden added a comment - - edited

          This permission issue seems to have weird side effects.

          After stashing a folder on windows and unstashing on linux, trying to change the persmission of the folder makes the filer impossible to delete.

          Here is a pipeline script to repoduce (crease a new job of type pipeline, add this to it).

          This is on jenkins v 2.277.3

           
          pipeline {
            agent { label 'windows' }
            stages {
              stage('windows') {
                steps {
                  sh 'hostname && pwd && env||sort' // debug
                   sh 'rm -rf folder1' // cleanup
                  // create folder with content
                  bat "mkdir folder1"
                  bat 'echo "TEST1" > folder1\\\test1.txt'
                  bat "mkdir folder1\\\\folder2" // double backslash for window, the formatting is messed up
                  bat 'echo "TEST2" > folder1\\\\folder2\\\\test2.txt'
                  stash includes: "folder1/*/", name: 'folder1_stash'
                }
              }
            stage('linux') {
                 agent { label 'ubuntu' }
                steps {
                  sh 'hostname && pwd && env||sort' // debug
                  sh 'ls -al'
                  unstash 'folder1_stash'
                  sh 'ls -al'
                  sh 'chmod -R 666 folder1 || true' // this line somehow causes folder1 to be impossible to delete, even though the chmod command fails.
                  sh 'rm -rf folder1' // fails
                }
              }
            }
          }

          Quentin Nerden added a comment - - edited This permission issue seems to have weird side effects. After stashing a folder on windows and unstashing on linux, trying to change the persmission of the folder makes the filer impossible to delete. Here is a pipeline script to repoduce (crease a new job of type pipeline, add this to it). This is on jenkins v  2.277.3   pipeline {   agent { label 'windows' }   stages {     stage('windows') {       steps {         sh 'hostname && pwd && env||sort' // debug          sh 'rm -rf folder1' // cleanup         // create folder with content         bat "mkdir folder1"         bat 'echo "TEST1" > folder1\\\test1.txt'         bat "mkdir folder1\\\\folder2" // double backslash for window, the formatting is messed up         bat 'echo "TEST2" > folder1\\\\folder2\\\\test2.txt'         stash includes: "folder1/* / ", name: 'folder1_stash'       }     }   stage('linux') {        agent { label 'ubuntu' }       steps {         sh 'hostname && pwd && env||sort' // debug         sh 'ls -al'         unstash 'folder1_stash'         sh 'ls -al'         sh 'chmod -R 666 folder1 || true' // this line somehow causes folder1 to be impossible to delete, even though the chmod command fails.         sh 'rm -rf folder1' // fails       }     }   } }

            Unassigned Unassigned
            dodoent Nenad Miksa
            Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: