14

I want to deploy to a ftp server using a Gitlab pipeline. I tried this code:

deploy: // You can name your task however you like
    stage: deploy
    only:
        - master
        deploy:
  script:
    - apt-get update -qq && apt-get install -y -qq lftp

But I get a error message. What is the best way to do this? :)

Daansk44
  • 497
  • 2
  • 4
  • 21
  • Try removing `deploy:` after the `- master` line. That seems to be misplaced. – wigy Apr 03 '18 at 14:04
  • deploy: // You can name your task however you like stage: deploy only: - master script: - apt-get update -qq && apt-get install -y -qq lftp I changed to this, but still does not work – Daansk44 Apr 03 '18 at 14:10

4 Answers4

26

Then add the following code in your .gitlab-ci.yml file.

variables:
  HOST: "example.com"
  USERNAME: "yourUserNameHere"
  PASSWORD: "yourPasswordHere"

deploy:
  script:
    - apt-get update -qq && apt-get install -y -qq lftp
    - lftp -c "set ftp:ssl-allow no; open -u $USERNAME,$PASSWORD $HOST; mirror -Rnev ./public_html ./ --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
  only:
    - master

The above code will push all your recently modified files in your Gitlab repository into public_html folder in your FTP Server root.

Just update the variables HOST, USERNAME and PASSWORD with your FTP Credentials and commit this file to your Gitlab Repository, you are good to go.

Now whenever you make changes in your master branch, Gitlab will automatically push your changes to your remote FTP server.

cglacet
  • 8,873
  • 4
  • 45
  • 60
Rustem Hesenov
  • 429
  • 5
  • 6
  • 15
    I would advise against putting your credentials within the yml file as it may be exposed. Instead, go to Settings -> CI/CD -> (Click on) Variables -> set your HOST, PASSWORD, and USERNAME variables there. Then, you can reference them within the yml file as you mention, but, in this way, you don't run the risk of exposing them. – Brad Ahrens Dec 04 '19 at 10:34
  • Which image do you use? – mohabbati Aug 09 '21 at 15:47
7

Got it :)

  image: mwienk/docker-git-ftp


    deploy_all:
      stage: deploy
      script:
        - git config git-ftp.url "ftp://xx.nl:21/web/new.xxx.nl/public_html"
        - git config git-ftp.password "xxx"
        - git config git-ftp.user "xxxx"
        - git ftp init
        #- git ftp push  -m "Add new content"

      only:
        - master
Daansk44
  • 497
  • 2
  • 4
  • 21
1

try this. There's a CI Lint tool in Gitlab that helps with formatting errors. The linter was showing an error, the additional deploy statement.

deploy:
  stage: deploy
  only:
    - master

  script:
    - apt-get update -qq && apt-get install -y -qq lftp
Tim Tharratt
  • 1,251
  • 1
  • 10
  • 18
0

I use this

deploy:
  script:
    - apt-get update -qq && apt-get install -y -qq lftp
    - lftp -c "set ftp:ssl-allow no; open -u $FTP_USERNAME,$FTP_PASSWORD $FTP_HOST; mirror -v ./ $FTP_DESTINATION --reverse --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
  environment:
    name: production
  only:
    - master
Rafa Sojo
  • 1
  • 1