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

Randomly named additional subfolder when checking out git

      When checking out (looking in job's console output), local files are getting not directly to the JobName@script folder but also add a subfolder with name like ecb7a9317b1ad672698830264d9e0ce2b9b6f330c043bb85f48623f3cdcab65e

      Checking out git git@...repo.git into /Users/user/.jenkins/workspace/JobName@script/ecb7a9317b1ad672698830264d9e0ce2b9b6f330c043bb85f48623f3cdcab65e/jenkins/A.groovy

       

      Loading the main groovy file here:

      Project to build located directly in Job Name folder, without subfolders. But scripts put in subfolder.

       

      Now, when in A.groovy I am trying to import B.groovy 

      load("jenkins/B.groovy")
      or
      load(env.WORKSPACE + "@script/jenkins/B.groovy"

      I am getting an error 

      java.nio.file.NoSuchFileException:
      /Users/user/.jenkins/workspace/JobName@script/jenkins/B.groovy

      And don't see any way to get that subfolder name from environment or other way. Thus just can't load an external file.

          [JENKINS-68287] Randomly named additional subfolder when checking out git

          This seems similar to JENKINS-67857, which was caused by the SECURITY-2441 or SECURITY-2463 fixes in Jenkins Security Advisory 2022-02-15.

          Which type of project are you using? What setting in the project causes A.groovy to be loaded?

          Kalle Niemitalo added a comment - This seems similar to JENKINS-67857 , which was caused by the SECURITY-2441 or SECURITY-2463 fixes in Jenkins Security Advisory 2022-02-15 . Which type of project are you using? What setting in the project causes A.groovy to be loaded?

          This issue has component = groovy-plugin and labels = pipeline workspace, but the Groovy plugin documentation says "Currently the plugin does not support pipeline syntax", so it's not clear to me whether the issue affects pipeline projects or freestyle projects.

          Kalle Niemitalo added a comment - This issue has component = groovy-plugin and labels = pipeline workspace, but the Groovy plugin documentation says "Currently the plugin does not support pipeline syntax", so it's not clear to me whether the issue affects pipeline projects or freestyle projects.

          Mark Waite added a comment -

          Assigned to the workflow-cps plugin because that is the plugin that implements the load step.

          Mark Waite added a comment - Assigned to the workflow-cps plugin because that is the plugin that implements the load step.

          Bogdan Cho added a comment - - edited

          Sorry if I've set wrong labels.
          I've attached screenshot in the description with the place where I am loading the main A.groovy file in jenkins. And additional screenshot with the folders structure. So, when the project is being built, there is no problems if I create the next code in the `fastfile`, because there is no unrecognisable additional subfolder inside the Job Name folder unlike the Job Name@script folder.

          slather(
           cobertura_xml: true,
           proj: "Project Name.xcodeproj", //relative path, file found correctly
           output_directory: "./test_output", //relative path, file is created in correct place
           scheme: scheme,
           jenkins: true
          )

          Bogdan Cho added a comment - - edited Sorry if I've set wrong labels. I've attached screenshot in the description with the place where I am loading the main A.groovy file in jenkins. And additional screenshot with the folders structure. So, when the project is being built, there is no problems if I create the next code in the `fastfile`, because there is no unrecognisable additional subfolder inside the  Job Name folder unlike the  Job Name@script folder. slather( cobertura_xml: true , proj: "Project Name.xcodeproj" , //relative path, file found correctly output_directory: "./test_output" , //relative path, file is created in correct place scheme: scheme, jenkins: true )

          Are A.groovy and B.groovy in the branch that is checked out to "workspace/Job Name"?

          If they are, then B.groovy should get checked out to "workspace/Job Name/jenkins/B.groovy" as well, and load(env.WORKSPACE + '/jenkins/B.groovy') should find it from there.

          If not, then perhaps you can use readTrusted to read 'jenkins/B.groovy' from SCM, writeFile to write that to a known path in the workspace, and finally load from there.

          Kalle Niemitalo added a comment - Are A.groovy and B.groovy in the branch that is checked out to "workspace/Job Name"? If they are, then B.groovy should get checked out to "workspace/Job Name/jenkins/B.groovy" as well, and load(env.WORKSPACE + '/jenkins/B.groovy') should find it from there. If not, then perhaps you can use readTrusted to read 'jenkins/B.groovy' from SCM, writeFile to write that to a known path in the workspace, and finally load from there.

          Bogdan Cho added a comment -

          Here is what I use to find the B.groovy file (sure, these files are in same repo and even same folder), but don't want to use that unnatural way.

          git_jenkins_folder = sh (
                  script: "find \"" + WORKSPACE + "\"@script -type d -name 'jenkins'",
                  returnStdout: true
              ).trim()
          
          utils = load("$git_jenkins_folder/B.groovy")
          

          You say `If they are, then B.groovy should get checked out to "workspace/Job Name/jenkins/B.groovy" as well`. No, as I mentioned in my issue, they both (whole project actually) are checked into
          /Users/user/.jenkins/workspace/JobName@script/ecb7a9317b1ad672698830264d9e0ce2b9b6f330c043bb85f48623f3cdcab65e/jenkins/A.groovy

          and

          /Users/user/.jenkins/workspace/JobName@script/ecb7a9317b1ad672698830264d9e0ce2b9b6f330c043bb85f48623f3cdcab65e/jenkins/B.groovy

          of course as these 2 are in same repo and folder. I am getting that extra ecb7a9317b1ad672698830264d9e0ce2b9b6f330c043bb85f48623f3cdcab65e subfolder as I've mentioned in the description on the 4th row.
          Project to build checked into workspace/Job Name/jenkins but later.
          First script is checked into workspace/Job Name@script/jenkins but with extra folder so we get workspace/Job Name@script/jenkins/ecb7a9317b1ad672698830264d9e0ce2b9b6f330c043bb85f48623f3cdcab65e

           

          Bogdan Cho added a comment - Here is what I use to find the B.groovy file (sure, these files are in same repo and even same folder), but don't want to use that unnatural way. git_jenkins_folder = sh ( script: "find \" " + WORKSPACE + " \ "@script -type d -name 'jenkins' " , returnStdout: true ).trim() utils = load( "$git_jenkins_folder/B.groovy" ) You say `If they are, then B.groovy should get checked out to "workspace/Job Name/jenkins/B.groovy" as well`. No, as I mentioned in my issue, they both (whole project actually) are checked into /Users/user/.jenkins/workspace/JobName@script/ecb7a9317b1ad672698830264d9e0ce2b9b6f330c043bb85f48623f3cdcab65e/jenkins/A.groovy and /Users/user/.jenkins/workspace/JobName@script/ecb7a9317b1ad672698830264d9e0ce2b9b6f330c043bb85f48623f3cdcab65e/jenkins/B.groovy of course as these 2 are in same repo and folder. I am getting that extra ecb7a9317b1ad672698830264d9e0ce2b9b6f330c043bb85f48623f3cdcab65e subfolder as I've mentioned in the description on the 4th row. Project to build checked into workspace/Job Name/jenkins but later. First script is checked into  workspace/Job Name@script/jenkins but with extra folder so we get  workspace/Job Name@script/jenkins/ecb7a9317b1ad672698830264d9e0ce2b9b6f330c043bb85f48623f3cdcab65e  

          Jesse Glick added a comment -

          As designed I think. The load step is for loading a file in an agent workspace, not on the controller.

          Jesse Glick added a comment - As designed I think. The load step is for loading a file in an agent workspace, not on the controller.

            Unassigned Unassigned
            bodich Bogdan Cho
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: