17

The shared library files in jenkins are loaded at the beginning of the job, where does it get stored? I am trying to access the dockerfile stored in the shared library, I need the path to give in the docker build command. Is there a way I can find out the place where the shared library files are loaded in jenkins?

AshJune
  • 183
  • 1
  • 2
  • 7

1 Answers1

20

If the shared library is loaded from SCM and your workspace path is jenkins/workspaces/jobName, then a copy is checked out to jenkins/workspaces/jobName@libs or similar (might be suffixed with a number if that path is occupied by another concurrent build).

However, there is another way, if I understand you correctly you wan't to retrieve a resource in this library? In that case you should use the libraryResource and writeFile steps. Like this:

writeFile file:'myFile.txt', text:libraryResource("path/to/myFile.txt")
Community
  • 1
  • 1
Jon S
  • 15,846
  • 4
  • 44
  • 45
  • What is the path I should use inside libraryResource? text:libraryResource("path/to/myFile.txt") How to find the path to the file in my resource? Can you be more clear about this? – AshJune Feb 26 '17 at 15:25
  • 1
    See here, https://jenkins.io/doc/book/pipeline/shared-libraries/#loading-resources, basically, if you, in your repo, have your file in `resources/path/to/myFile.txt` then you use `libraryResource("path/to/myFile.txt")`. E.g. the files are resolved relative to the `resources/` folder. – Jon S Feb 26 '17 at 15:34
  • Where will be the location of myFile.txt on the jenkins node ? – sirineBEJI May 24 '18 at 10:13
  • @codeGeass are you refering to {{writeFile file:'myFile.txt' ...}} then the file is written in current working directory. – Jon S May 24 '18 at 11:09
  • Yes, in the workspace ? Could not find it, so I have written {writeFile file:"${WORKSPACE}/myFile.txt" ...} – sirineBEJI May 24 '18 at 12:14
  • Strange... Were you inside a dir step? – Jon S May 24 '18 at 17:48
  • This was beacause I had stages on which I was specifying each time the agent, so Jenkins created a temporary workspace for each stage. So when I was reffering to that resource in an other stage, Jenkins could not find it because the workspace is different. – sirineBEJI Jul 04 '18 at 09:24
  • @codeGeass consider `stash`ing your files if you have multiple nodes/agents and need the files to persist from stage to stage regardless of the agent being used. – Max Cascone Jun 30 '20 at 20:33