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

readProperties java.exe locks properties file

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • Jenkins version 2.54 (java 8)
      pipeline-utility-steps version 1.3.0

      After upgrading to pipeline-utility-steps version 1.3.0 java.exe locks the properties file. I'm using a Jenkinsfile to read properties:

      stages {    
          stage('Build Projects') {
              steps {
                  script {
                      def properties = readProperties file: 'MyProject.properties'                
                  }
              }
          }
      }
      

      After running one build java.exe doesn't release the file lock so another checkout can't finish.

          [JENKINS-43568] readProperties java.exe locks properties file

          David Ringhofer added a comment - - edited

          I'm facing the same issue with readMavenPom

          rsandell, have you found a workaround to release the lock?

          David Ringhofer added a comment - - edited I'm facing the same issue with readMavenPom rsandell , have you found a workaround to release the lock?

          As a workaround I'm currently using something also the lines of:

          def version() {
              def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
              matcher ? matcher[0][1] : null
          }

          David Ringhofer added a comment - As a workaround I'm currently using something also the lines of: def version() { def matcher = readFile( 'pom.xml' ) =~ '<version>(.+)</version>' matcher ? matcher[0][1] : null }

          Justin McMillan added a comment - - edited

          I am also experiencing this issue using readProperties, and it's a major blocker for my pipeline jobs:

          1. Run a pipeline with a readProperties step
          2. Clearing the workspace containing the file from the Jenkins front-end leaves a zero byte file along with throwing a Jenkins 'access denied' error
          3. Updating the workspace from SVN, I get an access denied error on that file when syncing
          4. The workspace is unusable until the Jenkins service is restarted, then the file locks are released

          Below are steps to reproduce the SVN update:

          • Create a pipeline with an SCM checkout step (use svn update as much as possible option) to check out a property file, and a readProperties step on that file
          • Run the pipeline once
          • Make a change to the file and commit
          • Run the pipeline job again, and the access denied error is thrown (see attached log svn-update-stack-trace.log)

          I am using Jenkins v2.60.1 and the Pipeline Utility Step is v1.3.0.

           

           

          I've been working on moving a lot of code out of the pipelines themselves and into Groovy libraries – I made a method to return a Properties object given a properties file, and it seems to be working pretty well (no locked files). Not the most graceful solution, but it worked conveniently for me:

          @NonCPS
          static Properties getPropertiesFromFile(String filepathStr) {
             Properties properties = new Properties()
             File filepath = new File(filepathStr)
          
             try {
                filepath.withInputStream {
                   properties.load(it)
                }
             } catch(Exception ex) {
                 ex.printStackTrace()
             }
             return properties
          }
          

           

          Justin McMillan added a comment - - edited I am also experiencing this issue using readProperties, and it's a major blocker for my pipeline jobs: Run a pipeline with a readProperties step Clearing the workspace containing the file from the Jenkins front-end leaves a zero byte file along with throwing a Jenkins 'access denied' error Updating the workspace from SVN, I get an access denied error on that file when syncing The workspace is unusable until the Jenkins service is restarted, then the file locks are released Below are steps to reproduce the SVN update: Create a pipeline with an SCM checkout step (use svn update as much as possible option) to check out a property file, and a readProperties step on that file Run the pipeline once Make a change to the file and commit Run the pipeline job again, and the access denied error is thrown (see attached log  svn-update-stack-trace.log ) I am using Jenkins v2.60.1 and the Pipeline Utility Step is v1.3.0.     I've been working on moving a lot of code out of the pipelines themselves and into Groovy libraries – I made a method to return a Properties object given a properties file, and it seems to be working pretty well (no locked files). Not the most graceful solution, but it worked conveniently for me: @NonCPS static Properties getPropertiesFromFile( String filepathStr) { Properties properties = new Properties() File filepath = new File(filepathStr) try { filepath.withInputStream { properties.load(it) } } catch (Exception ex) { ex.printStackTrace() } return properties }  

          David Yerkess added a comment -

          I also experienced the same problem with 1.3.0.

          Instead of reverting to 1.2.2, I switched to everything to readJSON that does not suffer the same problem.

          David Yerkess added a comment - I also experienced the same problem with 1.3.0. Instead of reverting to 1.2.2, I switched to everything to readJSON that does not suffer the same problem.

          Peter Kranz added a comment -

          I have created a pull request for this issue: https://github.com/jenkinsci/pipeline-utility-steps-plugin/pull/28

          I've added try-with-resource blocks so that the opened streams get closed accordingly

          Peter Kranz added a comment - I have created a pull request for this issue: https://github.com/jenkinsci/pipeline-utility-steps-plugin/pull/28 I've added try-with-resource blocks so that the opened streams get closed accordingly

          Code changed in jenkins
          User: Peter J. Kranz
          Path:
          src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/ReadPropertiesStepExecution.java
          src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/mf/ReadManifestStepExecution.java
          src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/maven/ReadMavenPomStep.java
          http://jenkins-ci.org/commit/pipeline-utility-steps-plugin/edae388722ea6143f3feb7174e78de75b1b3d2b2
          Log:
          JENKINS-43568: readProperties java.exe locks properties file

          adding try-with-resource blocks to FilePath#read calls

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Peter J. Kranz Path: src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/ReadPropertiesStepExecution.java src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/mf/ReadManifestStepExecution.java src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/maven/ReadMavenPomStep.java http://jenkins-ci.org/commit/pipeline-utility-steps-plugin/edae388722ea6143f3feb7174e78de75b1b3d2b2 Log: JENKINS-43568 : readProperties java.exe locks properties file adding try-with-resource blocks to FilePath#read calls

          Daniel Baum added a comment -

          I am experiencing this issue with readMavenPom locking pom.xml files.  I recursively find all pom.xml files in a project to get information out of them.  When I run a build for a second time it finds pom.xml files within the maven target folder and then causes the 'mvn clean install' command to fail since maven cannot completely delete the target folder because the readMavenPom function has locked those extra pom files.

          Daniel Baum added a comment - I am experiencing this issue with readMavenPom locking pom.xml files.  I recursively find all pom.xml files in a project to get information out of them.  When I run a build for a second time it finds pom.xml files within the maven target folder and then causes the 'mvn clean install' command to fail since maven cannot completely delete the target folder because the readMavenPom function has locked those extra pom files.

          rsandell added a comment -

          dabauum221 What version are you on? This issue should have been fixed in 1.4.0.

          rsandell added a comment - dabauum221 What version are you on? This issue should have been fixed in 1.4.0.

          Daniel Baum added a comment -

          We are on version 1.3.0. Thanks for the reply. I will upgrade when we have a chance to test the build and see if that fixes it.

          Daniel Baum added a comment - We are on version 1.3.0. Thanks for the reply. I will upgrade when we have a chance to test the build and see if that fixes it.

            rsandell rsandell
            dutchcode Dutch Code
            Votes:
            3 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated: