Create Jenkins Directory

I want to know if there is a function or pipeline plugin that allows you to create a directory in the workspace instead of using sh "mkdir directory" ?

I tried using the groovy new File("directory").mkdirs() , but it always new File("directory").mkdirs() exception.

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: scripts are not allowed to use the new java.lang.RuntimeException java.lang.String

+15
jenkins jenkins-pipeline
source share
2 answers

What you can do is use the dir step, if the directory does not exist, then the dir step will create the folders needed after you write the file or something like that:

 node { sh 'ls -l' dir ('foo') { writeFile file:'dummy', text:'' } sh 'ls -l' } 

The sh steps are here to show that the folder is created. The disadvantage is that you will have a dummy file in the folder (a dummy entry is not needed if you are going to write other files). If I run this, I get the following output:

 Started by user jon [Pipeline] node Running on master in /var/lib/jenkins/workspace/pl [Pipeline] { [Pipeline] sh [pl] Running shell script + ls -l total 0 [Pipeline] dir Running in /var/lib/jenkins/workspace/pl/foo [Pipeline] { [Pipeline] writeFile [Pipeline] } [Pipeline] // dir [Pipeline] sh [pl] Running shell script + ls -l total 4 drwxr-xr-x 2 jenkins jenkins 4096 Mar 7 22:06 foo [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS 
+46
source share

Just use the file operations plugin .

 fileOperations([folderCreateOperation('directoryname')]) 
0
source share

All Articles