Working with distributed builds

30 views
Skip to first unread message

Rajeev Ranjan

unread,
Jun 9, 2019, 4:04:50 PM6/9/19
to Jenkins Developers
Hi team,
I am stuck at end which currently I don't have clue how to proceed.
I have a plugin which is having some powershell files as resources in the jar (generated at build time).
During runtime
  1. it extracts the plugin jar from $JENKINS_HOME to get powershell files
  2. execute it to perform business logic of the plugin on the project
  3. generates the output file in the provided path.
It works perfectly fine if it is only master.The problem here with this is it fails in distributed architecture as it won't have .

What solution I can think of is to
  1. copy the plugin to slave,
  2. extract the files and execute the powershell files in slave instance,
  3. and copy back the output to master/slave as per input?
I am not sure how to copy the files between master/slave, any reference would be appreciated.
Also I am not sure even if this would work, is this the correct way for the whole procedure (extracting the powershell files from jar, copying between slave/master and executing it in slave).

Regards,
Rajeev Ranjan

Ivan Fernandez Calvo

unread,
Jun 10, 2019, 5:33:55 AM6/10/19
to Jenkins Developers
There is a plugin that copies files in the workspace, that it is what you want see https://plugins.jenkins.io/config-file-provider

Jesse Glick

unread,
Jun 10, 2019, 10:25:21 AM6/10/19
to Jenkins Dev
On Sun, Jun 9, 2019 at 4:04 PM Rajeev Ranjan <rajeevr...@gmail.com> wrote:
> it extracts the plugin jar from $JENKINS_HOME to get powershell files
> execute it to perform business logic of the plugin on the project

Use

https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getResource-java.lang.String-
https://javadoc.jenkins.io/hudson/FilePath.html#copyFrom-java.net.URL-

to copy a plugin resource to a remote location. You probably also want to use

https://javadoc.jenkins.io/hudson/slaves/WorkspaceList.html#tempDir-hudson.FilePath-

so that you do not pollute the user’s workspace.

Rajeev Ranjan

unread,
Jul 8, 2019, 1:38:19 PM7/8/19
to Jenkins Developers

Thanks Ivan and Jesse for help,

Got to know that FilePath is the key to access file in Jenkins Infra. It has exposed several encapsulated methods to handle such issues of copying from Master to slave and vice versa. Definitely would recommend anyone to go through reference suggested by Jesse.
Also to execute powershell commands, I took the help of Powershell Plugin's / CommandInterpreter perform step instead of going with your own step, thus can reduce code duplication a lot.

Regards,
Rajeev Ranjan
Reply all
Reply to author
Forward
0 new messages