2

I have recently started to mess about with Jenkins and am unsure how to deploy my web app to a basic server. I've gotten into the Pipeline (https://jenkins.io/doc/book/pipeline/) and it seems like a fantastic way to work.

Where I'm a bit stuck is in two spots:

  1. Once my repo is in my workspace within Jenkins, how do I prep it so I am only deploying the files necessary for the application? For example, I don't need my src/ directory or my Vagrantfile when I'm deploying things.
  2. How do I deploy my app to the server? I see examples all over the place, but I am getting a bit lost since there seems to be so many ways to do this. I'm assuming scp or something like that...?

To build off of #2, is there a way to deploy web apps as transactions (in one shot) rather than file-by-file?

Please let me know if I can provide any information for potential answers!

Gurnzbot
  • 3,742
  • 7
  • 36
  • 55

3 Answers3

0

I can't speak to your specific use case but a common way to do this is the build-and-deploy model, where you will have 2 Jenkins jobs. The "build" job will check out from source, run build commands such as maven or make, and lastly will "archive" the build artifacts. The latter is an option under the 'post-build actions' tab at the bottom.

In the "deploy" job, you will grab the artifacts of your choice. You can fetch a single file, all of them, and everything in between. This requires use of the 'Copy Artifact' plug-in and it allows you to copy files generated by other jobs. Now you can run your usual deploy script in the 'Execute Command' box. Most command line paradigms are supported out of the box such as setting environment variables.

The instructions above assume that you want to run your application off of a host that you've provisioned as a Jenkins slave.

Paul Back
  • 1,269
  • 16
  • 23
0
  1. Use artifacts as mentioned by Paul Back, or a 3rd party artifactory server as in video

  2. This is always tricky and error-prone. Why not spin up a fresh server with new release (humanly verified once)

Community
  • 1
  • 1
SACn
  • 1,862
  • 1
  • 14
  • 29
0

Jenkins & Ansible is the answer here. This is how I deploy to production, since I am in no need to use anything like Docker (too many issues with particular app) so have to run the app natively. Quick example would be

You monitor a specific branch in gitlab / github or whatever else and then call a webhook on push / merge etc on that branch, at this point you deal with anything you need to do by running a playbook on the jenkins job that monitors that branch (jenkins).

in my case jenkins and ansible run on the same server. Jenkins runs the ansible playbook that does whatever I need to do.

for example with ansible, I copy certain files that need to be there, run configs / change filenames etc. setup nginx, run composer,

you get the point.

megachill
  • 225
  • 1
  • 3
  • 12