1

I have a static website that I would like to deploy to my Apache2 server using Jenkins. I think of 2 solutions:

  • Should I change the workspace dir of Jenkins to /var/www/?
  • Or should I copy all files in workspace to /var/www in post build?
1

As mentioned, there are many ways to accomplish the final goal of exposing a site built from a Jenkins job to public traffic.

Both ideas could work, but here are some tweaks.

  • Instead of changing the job workspace directory, build the site to a sub directory in the workspace and symlink the directory with root directory of your site. This allows control over what is part of live site.
  • To put a boundary between the build and deploy, rsync would be more efficient and easier to manage than copying. Follow the same pattern of creating a sub directory and rsync to the site directory.

The decision depends on the requirements of the site. If it is static with no promise of up-time, a symlink will work fine, however if the Jenkins job breaks and breaks the workspace version of the site, the actual site will be down. I would recommend using rsync and adding a validation step between the build and rsync to ensure the site stays up.

Final note, using git or other scm provides backups which can be tagged. If the current build breaks, rolling back would be easy. However, if there is no scm (not recommended), keep some segregation between the build and live site to ensure it is not broken for an extended amount of time.

6
  • Thank you for your advices. I'm using git now, so the rolling back is no problems. But this is a static website, so there is actually no build stage in this project? Just put all files inside Apache server and it would be fine? Because I don't know how we can validate the static website. In this case, does that mean build and deploy stage are the same? So should I use symlink in this project?
    – Black2910
    Feb 23 '20 at 1:06
  • If there is no build, I am assuming you are just pulling from the git repository (.html, .css, etc.) and putting into the root folder for website on the Apache Webserver. Jenkins can do all of that for you, but it is quite a bit of overhead just to serve static pages without any builds, validation or testing. Can you use pages.github.com ?
    – George
    Feb 23 '20 at 1:57
  • Yes, but this is for a large company, so they required me to use Jenkins for this project. Although I know it is a little bit overhead. "I am assuming you are just pulling from the git repository (.html, .css, etc.) and putting into the root folder for website on the Apache Webserver. Jenkins can do all of that for you": That's correct, so follow your words, what is the best way to do that?
    – Black2910
    Feb 23 '20 at 8:14
  • Btw I'm also using github webhook to trigger Jenkins too.
    – Black2910
    Feb 23 '20 at 8:16
  • With the information your have provided, I would recommend using rsync to keep segregation between your workspace and the root of your website. It ensures your builds are modular, meaning you can add additional parts or sites by rsyncing folders from other jobs without managing symlinks on the system.
    – George
    Feb 23 '20 at 18:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.