7

I was wondering how to get my web-projects deployed using ftp and/or ssh.

We currently have a self-made deployment system which is able to handle this, but I want to switch to Jenkins.

I know there are publishing plugins and they work well when it comes to uploading build artifacts. But they can't delete or move files.

Do you have any hints, tipps or ideas regarding my problem?

4eyes
  • 661
  • 2
  • 6
  • 5

3 Answers3

3

The Publish Over SSH plugin enables you to send commands using ssh to the remote server. This works very well, we also perform some moving/deleting files before deploying the new version, and had no problems whatsoever using this approach.

pushy
  • 9,535
  • 5
  • 26
  • 45
  • Thanks, that will probably help me with my ssh servers.But how do you get the information which files need to be moved / deleted? Git certainly knows it, but how to integrate this in the deployment workflow? – 4eyes Nov 22 '11 at 12:22
  • If the files you are interested in moving/deleting are already in git, you could just clone your repo on your deployment servers, and use git command line to pull the changes using publish over ssh. This might be a good way to go if you have static files, which do not need to be compiled or checked, just need deployment. Would probably work best if you have separate repos for source code and static files. – pushy Nov 23 '11 at 12:45
  • Thanks. Our projects are all "static" files as we develop php (TYPO3) based software. I'm aware that I can get the moved / deleted files using git, actually that's what we've been doing in our own simple phing based deployment system. I'm just anstonished, that there does not seem to be a plugin covering clean and efficient ftp/ssh deployment. I'm wondering how other companies deploy their web-projects, don't they use ftp(s)? Or just more expensive customised hosting with ssh and/or git on the live server? – 4eyes Nov 23 '11 at 19:25
1

The easiest way to handle deleting and moving items is by deleting everything on the server before you deploy a new release using one of the 'Publish over' extensions. I'd say that really is the only way to know the deployed version is the one you want. If you want more versioning-system style behavior you either need to use a versioning system or maybe rsync that will cover part of it.

If your demands are very specific you could develop your own convention to mark deletions and have them be performed by a separate script (like you would for database changes using Liquibase or something like that).

By the way: I would recommend not automatically updating your live sites after every build using the 'publish over ...' extension. In case we really want to have a live site automatically updated we rely on the Promoted Builds Plugin to keep it nearly fully-automated but add a little safety.

Simon Groenewolt
  • 10,607
  • 1
  • 36
  • 64
  • Thank you Simone for your advice, I will check the promoted build plugin. Anyway, it just doesn't make sense to me, why I need upload a complete website, when I simply changed a little css or fixed a bug in a script. Somehow, I seem the only one having this problem or everybody else either deploys their website projects to a fancier hosting (ssh / git) or isn't using automated deployment. – 4eyes Nov 23 '11 at 06:38
0

I came up with a simple solution to remove deleted files and upload changes to a remote FTP server as a build action in Jenkins using a simple lftp mirror script. Lftp Manual Page

In Short, you create a config file in your jenkins user directory ~/.netrc and populate it with your FTP credentials.

machine ftp.remote-host.com
login mySuperSweetUsername
password mySuperSweetPassword

Create an lftp script deploy.lftp and drop it in the root of your .git repo

set ftp:list-options -a
set cmd:fail-exit true
open ftp.remote-host.com
mirror --reverse --verbose --delete --exclude .git/ --exclude deploy.lftp  --ignore-time --recursion=always

Then add an "Exec Shell" build action to execute lftp on the script.

lftp -f deploy.lftp

The lftp script will

  • mirror: copy all changed files
  • reverse: push local files to a remote host. a regular mirror pulls from remote host to local.
  • verbose: dump all the notes about what files were copied where to the build log
  • delete: remove remote files no longer present in the git repo
  • exclude: don't publish .git directory or the deploy.lftp script.
  • ignore-time: won't publish based on file creation time. If you don't have this, in my case, all files got published since a fresh clone of the git repo updated the file create timestamps. It still works quite well though and even files modified by adding a single space in them were identified as different and uploaded.
  • recursion: will analyze every file rather than depending on folders to determine if any files in them were possibly modified. This isn't technically necessary since we're ignoring time stamps but I have it in here anyway.

I wrote an article explaining how I keep FTP in sync with Git for a WordPress site I could only access via FTP. The article explains how to sync from FTP to Git then how to use Jenkins to build and deploy back to FTP. This approach isn't perfect but it works. It only uploads changed files and it deletes files off the host that have been removed from the git repo (and vice versa)

Houghtelin
  • 386
  • 3
  • 5