Jenkins installed on Ubuntu 18.04 and running successfully.

As part of our project build process, we need to copy built files to a specific folder under /var/www/html (Apache folder). Our build / Execute shell:

npm install ng build --prod cp -R /var/lib/jenkins/workspace/kagi-core/dist/core/* /var/www/html/kagi-core/ 

But jenkins build fails at the final copy command with the following errors:

23:18:10 + cp -R /var/lib/jenkins/workspace/kagi-core/dist/core/3rdpartylicenses.txt /var/lib/jenkins/workspace/kagi-core/dist/core/assets ... 23:18:10 cp: cannot create regular file '/var/www/html/kagi-core/3rdpartylicenses.txt': Permission denied ... ... 

Here's what we did/tried so far:

  1. Added "jenkins" user to root and ubuntu groups.

    ubuntu@ip-172-31-15-215:/var/www/html$ groups jenkins jenkins : jenkins root ubuntu 
  2. Changed permissions on /var/www/html/kagi-core folders to "jenkins" user

    drwxr-xr-x 3 ubuntu jenkins 4096 Sep 17 21:36 www .. drwxr-xr-x 3 ubuntu jenkins 4096 Sep 18 21:04 html .. drwxrwxrwx 4 ubuntu jenkins 4096 Sep 18 21:18 kagi-core 

What are we missing? Appreciate any help!

1 Answer

While trying to fix this, found the solution. Adding here for reference:

On observing carefully, the permissions to /var/www folders, they are as

drwxr-xr-x 3 ubuntu jenkins 4096 Sep 17 21:36 www

but instead they should be the other way around (allow "jenkins" user to the default group):

drwxr-xr-x 3 jenkins ubuntu 4096 Sep 17 21:36 www

Also we reset the group to default root

So the command that solved the issue was

cd /var sudo chown -R jenkins:root www/ 

After this, jenkins builds were successful (able to copy to the /var/www/html folder).

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy