Pipeline - how to copy a directory of files from outside of workspace into a workspace using groovy?

4,124 views
Skip to first unread message

bbyjenkns

unread,
Aug 2, 2017, 10:26:01 AM8/2/17
to Jenkins Users
We have a somewhat different use case where we have a bunch of common config and build related files on NFS mount that need to be copied into each build workspace. What I need to do is copy a directory out of this NFS location and into workspaces as needed, a different directory per build type. 

Ideally I do this in groovy so I can get better exception handling and not be tied to OS specific commands, but everything I've tried is breaking, included the groovy preferred AntBuilder.copy() method.

How would you copy a directory of files from outside of a workspace into a workspace?

Cuong Tran

unread,
Aug 2, 2017, 1:38:37 PM8/2/17
to Jenkins Users
You can't use normal groovy api since it only works on master.  Since you're already using unix slaves, just use a normal shell step will save you headaches.

jer...@bodycad.com

unread,
Aug 2, 2017, 2:28:04 PM8/2/17
to Jenkins Users
It's not as funny as it should be for a build system manipulating file should be fairly easy. There is no direct way, but here a solution that would probably work I haven't test it:
  1. Zip the folder into a single file from the particular source node
  2. statch the file (or maybe if the **/* ant work you could try to stash the whole directory) from the source node
  3. unstash it on the wanted target node
  4. unzip it (if not stash a dir)
That should work and copy the source directory into target properly, at least I hope.

bbyjenkns

unread,
Aug 3, 2017, 4:09:12 PM8/3/17
to Jenkins Users
You can't use normal groovy api since it only works on master.  Since you're already using unix slaves, just use a normal shell step will save you headaches.

Why does the groovy api only work on master, but the sh step does? What is the point of having a global pipeline if it can only run on master? 

Stephen Connolly

unread,
Aug 3, 2017, 5:21:23 PM8/3/17
to jenkins...@googlegroups.com
On Thu 3 Aug 2017 at 21:09, bbyjenkns <mcj...@gmail.com> wrote:
You can't use normal groovy api since it only works on master.  Since you're already using unix slaves, just use a normal shell step will save you headaches.

Why does the groovy api only work on master, but the sh step does? What is the point of having a global pipeline if it can only run on master? 

The CPS "groovy" is only executed on master. You can use loads of different steps in a node block to target that step at executing on the node... but it depends on the actual step to fork processes...

Depending on how the step was written to fork the process you may lose the "restartable jenkins" property of pipelines, e.g. If not based on durable task api, or if not idempotent

Which is another reason not to think of pipeline as "groovy"

On Wednesday, August 2, 2017 at 12:38:37 PM UTC-5, Cuong Tran wrote:
You can't use normal groovy api since it only works on master.  Since you're already using unix slaves, just use a normal shell step will save you headaches.

On Wednesday, August 2, 2017 at 7:26:01 AM UTC-7, bbyjenkns wrote:
We have a somewhat different use case where we have a bunch of common config and build related files on NFS mount that need to be copied into each build workspace. What I need to do is copy a directory out of this NFS location and into workspaces as needed, a different directory per build type. 

Ideally I do this in groovy so I can get better exception handling and not be tied to OS specific commands, but everything I've tried is breaking, included the groovy preferred AntBuilder.copy() method.

How would you copy a directory of files from outside of a workspace into a workspace?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/4e6d402b-6301-4399-8efb-0fa7d63c005a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Sent from my phone
Reply all
Reply to author
Forward
0 new messages