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

<p>Both ideas could work, but here are some tweaks.</p>

<ul>
<li>Instead of changing the job workspace directory, build the site to a sub directory in the workspace and <a href="https://devdojo.com/tutorials/what-is-a-symlink" rel="nofollow noreferrer">symlink</a> the directory with root directory of your site. This allows control over what is part of live site.</li>
<li>To put a boundary between the build and deploy, <a href="https://www.samba.org/ftp/rsync/rsync.html" rel="nofollow noreferrer">rsync</a> 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. </li>
</ul>

<p>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.</p>

<p>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.</p>

CC BY-SA 4.0
2020-02-23T01:06:23.217Z
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
CC BY-SA 4.0
2020-02-23T01:57:34.397Z
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 https://pages.github.com/ ?
George
CC BY-SA 4.0
2020-02-23T08:14:19.093Z
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
CC BY-SA 4.0
2020-02-23T08:16:10.790Z
Btw I'm also using github webhook to trigger Jenkins too.
Black2910
CC BY-SA 4.0
2020-02-23T18:15:14.650Z
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
CC BY-SA 4.0
2020-02-24T14:24:27.513Z
Thank you so much. I will do that.
Black2910
CC BY-SA 4.0
2020-02-23T00:01:01.100Z
2020-02-23T00:01:01.100Z
George
<p>I have a static website that I would like to deploy to my Apache2 server using Jenkins. I think of 2 solutions: </p>

<ul>
<li>Should I change the workspace dir of Jenkins to /var/www/?</li>
<li>Or should I copy all files in workspace to /var/www in post build?</li>
</ul>

<jenkins><apache-httpd>
Jenkins deploy static web with Apache2
Black2910
# Jenkins deploy static web with Apache2

(Asked by: username_0 on 2020-02-22)

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?

**Tags:** jenkins, apache-httpd


---

## 1 answers

### Answer by username_1 on 2020-02-23. Score: 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](https://devdojo.com/tutorials/what-is-a-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](https://www.samba.org/ftp/rsync/rsync.html) 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.

> **Comments:**
> **username_0**: 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?  
> **username_1**: 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 https://pages.github.com/ ?  
> **username_0**: 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?  
> **username_0**: Btw I'm also using github webhook to trigger Jenkins too.  
> **username_1**: 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.  
> **username_0**: Thank you so much. I will do that.  

---

