Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Gitlab Pipeline to push data to ftpserver

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? :)

like image 316
Daansk44 Avatar asked Apr 03 '18 14:04

Daansk44


People also ask

How do you run a pipeline for a Commit in GitLab?

Execute a pipelineEvery commit pushed to GitLab generates a pipeline attached to that commit. If multiple commits are pushed together, a pipeline is created for the last commit only. To start a pipeline for demonstration purposes, commit and push a change directly over GitLab's web editor. Now commit your changes.

How does GitLab CI CD pipeline work?

A pipeline is usually triggered by a source code repository. Changes in code activate a notification in the CI/CD pipeline tool, which operates the corresponding pipeline. Other triggers you might see frequently include user-initiated or automatically scheduled workflows, as well as results of other pipelines.

Can we deploy using GitLab?

With GitLab CI, you can flexibly specify which branches to deploy to. If you deploy to multiple environments, GitLab will conserve the history of deployments, which allows you to rollback to any previous version.


1 Answers

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.

like image 72
Rustem Hesenov Avatar answered Nov 09 '22 22:11

Rustem Hesenov