Copy code to Jenkins container workspace

I am trying to push project code (on my mac) to Jenkins Container running on my mac.

To do that: In Jenkins Container, I have installed SCM plugin : File System SCM. But Jenkins gives error while copying project code from host system to jenkins workspace (Jenkins container).

FSSCM.checkout /Users/userTest/Documents/personal/regression/ to 
/var/jenkins_home/workspace/regression-test
FATAL: Parameter 'directory' is not a directory
java.lang.IllegalArgumentException: Parameter 'directory' is not a directory

How to copy code from host to Jenkins container? OR
How Jenkins container workspace can pull code from my host machine location?

The SCM plugin gives Jenkins access to the filesystem that Jenkins is running at, in this case the container filesystem. To allow the Jenkins container to access your host filesystem, you need to mount a volume into your Jenkins container on startup. In your case, the container has no clue where to find the /Users/-directory.

As an example, we mount the jenkins data directory to a mfs drive that is mounted on all our nodes, so regardless of where Jenkins is started, it can find the data.

–mount type=bind,source=/mnt/efs/docker-data/jenkins,destination=/var/jenkins_home

You could mount your /Users/userTest/ into the Jenkins container and then SCM from there. Or just mount the directory directly into the workspace.

1 Like

Thanks for the solution. I got stuck in different issue now. As per project req - I don’t want to mount my host directory to Jenkins container. So, i used below command to copy all my project code files like this:

docker cp /Users/pranaytgupta/Documents/regression-test ce8a9add0f80:/var/jenkins_home/workspace/zalenium-test/

This created a folder called regression-test inside Jenkins Workspace : zalenium-test/regression-test

Now, when i doing npm install in Jenkins job (container): it fails to install node_modules. But if change my jenkins workspace to point to the directory zalenium-test , i am able to install all node modules. But this won’t run my gulp file as it is inside regression-test folder. And I cannot copy all files and folders from regression-test to outside this folder in container. Permission denied.

Any solution to tackle this?

Well. I wouldn’t copy things into Jenkins, I would use a SCM like Git. Even if you have a Git Repository on the local machine, it would be easier for Jenkins to communicate with your host.

Another solution would be to be in the regression-test folder and do

docker cp * ce8a9add0f80:/var/jenkins_home/workspace/zalenium-test

This is due to how the docker cp command works.

1 Like