2

I'm trying to read some file in a certain job. Using Script Console in Jenkins I see the follow:

  • Jenkins can access the necessary build in a job

file = new File ("${Jenkins.instance.getItemByFullName('Build mac pipelines/sand box').lastBuild}")

The result will be:

Result: Build mac pipelines/sand box #44

  • But when I try to read the file groovy1.txt like this:

file = new File ("${Jenkins.instance.getItemByFullName('Build mac pipelines/sand box').lastBuild}/groovy1.txt").text

then Jenkins can't find groovy1.txt file

Build mac pipelines/sand box #44/groovy1.txt (No such file or directory)

It happens while such file exists, screenshot

screenshot

Why it happens and how to read the file ?

Igor Vlasuyk
  • 514
  • 2
  • 10
  • 22

1 Answers1

0

The workspace path does not contain the build number.

Each build uses the same workspace.

If possible look at the filesystem of the machine, where Jenkins is installed.

EDIT

If I remember correctly you don't even need the absolute path of the workspace, you could try file = new File ("./groovy1.txt").text.

Please check also here for some suggestions: Get absolute path to workspace directory in Jenkins Pipeline plugin

Simon
  • 1,616
  • 2
  • 17
  • 39
  • ok, the new command will be `file = new File ("${Jenkins.instance.getItemByFullName('Build mac pipelines/sand box')}/groovy1.txt").text` and the result `java.io.FileNotFoundException: org.jenkinsci.plugins.workflow.job.WorkflowJob@301b99ab[Build mac pipelines/sand box]/groovy1.txt (No such file or directory)` – Igor Vlasuyk Jan 16 '20 at 11:46
  • I need absolute path, because I'm going to read file from another job. – Igor Vlasuyk Jan 16 '20 at 11:57
  • Ok, then you should check the link I provided. In addition I don't think the hierarchy `Build mac pipelines/sand box` provided in the web interface matches with the actual file system. – Simon Jan 16 '20 at 12:08