0%

[jenkins] Sharing files between jenkins master and slave nodes

Sometimes you may want to share files between your jenkins master and slave nodes.

For example, maybe I have a powershell script, test.ps1, which contains some frequently called functions.

# test.ps1

function foo {
  echo "bar"
}

One way to share this file is save it at master, and copy it to slave node before it is called by slave node. This would require many jenkins configurations.

Recently I found that this can be easily done with Config File Provider Plugin.

First you need to install the plugin. After it is installed, you can find Managed files at http://JENKINS_URL/manage. Click it.

Managed files

Then define your shared file by clicking Add a new Config -> Custom file

Add a new Config

Custom file

Now you are going to define the name and content of the shared file.

Custom file

Now the file is ready to be used by your jenkins projects.

Inside your project, you can find a Provide Configuration files option. Check it.

Custom file

Let’s take a look at the options here. File means the shared file you just defined.

Jenkins will create the File at the folder specified by Target (In my case, I specify the folder to be the workspace of my project).

Remember to make sure that the folder exists before building the project.

Variable represents an environment variable with which you can refer to the file.

Now you can import this file no matter whether you are at master or slave node.

Import Excute

. $env:util imports the file. This makes powershell recognize foo command.