shellubuntujenkinscentosjenkins-cli

How can i deploy my web application in apache using jenkins?


I have to deploy my web application (which is made in React) in Apache2 using Jenkins.

I want jenkins instead of redirecting the repository data to "Building in workspace /var/jenkins_home/workspace/" to automatically redirect them to "/var/www/" and build the build there when a push is made and so on updating the website automatically.

I've been looking for many parts and I can't find information that can help me, I don't know if it's possible.

I use Ubuntu as operating system, but later I will deploy the Jenkins server to CentOS Stream.

So information for either one can work for me.

Try using bash command but it didn't work

"dir("folder") { sh "pwd" }"

In folder I added the path to "/www/var/home/osboxes/jenkins/var/jenkins_home/workspace/CI - CD" but it gave me the following error:

enter image description here


Solution

  • In oders of complexity:

    1. You can use jenkins publish over ssh plugin to copy your folder from the workspace to the remote server. You must generate a key your jenkins server and copy it on the deployment target. ( don't use user/pass as it is very insecure) .
    2. you can make a small ansible role that jenkins can use to: connect to the server , backup the existing folder with a timestamp, delete old backups , copy the new content from workspace and restart the server.
    3. dockerize your app, push your image and make jenkins run a remote command on the remote server to update the running container. If you use tags , the rollbacks will be easy . This way downtime is very low (seconds)

    For all these try to use jenkins pipelines as code and commit your jenkinsfile in the project code.