skip to Main Content

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

2

Answers


  1. 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.

    Login or Signup to reply.
  2. I deploy the file via FTP to the apache server, but now I want to automate it with jenkins.

    Great, so deploy the file via FTP to the apache server with Jenkins. There is a command lftp. I typically use docker image with commands that I need, like https://hub.docker.com/r/minidocks/lftp .

    docker.image('minidocks/lftp').inside() {
        # h
        sh 'lftp -u login,password yourapacheserver.host.com -e "put  ./yourfile ; exit "'
    }
    

    I would put that lftp command line in a script so you can test it locally first.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search