Gitlab CI to deliver files to a remote server (rsync)

Viewed 2015

I'm working with SVN but I would like to move on to Git, and more specifically to Gitlab.

I have the following structure:

MyStructure/
  customer/
    client1/
      delivery.sh
      MyFiletoSend.sh
    client2/
      delivery.sh
      MyFiletoSend2.sh

Currently, the "delivery.sh" will send the modifications (rsync) of the file "MyFiletoSend.sh" to the server "client1".

Can I run the "delivery.sh" via Gitlab automatically after/before the git push only on the files modified in this push?

Example:

  • I have a modification to make to the file "MyFiletoSend.sh" from client1/
  • I make my change
  • commit and push
  • Gitlab is running "delivery.sh" on my "client1/" file.
  • The file "MyFiletoSend.sh" is sent to the server of "client1" without touching "client2".
2 Answers

Assuming your delivery.sh scripts have all the rsync logic required, GitLab has built-in logic to detect changes in files and execute bash commands in response. You can create a separate job for each client, which can run in parallel in the same stage. This approach is also auditable in that it will clearly show you which clients got updated and with which version of the file.

update-client-1:
  stage: update-clients
  only:
    changes:
      # Detect change only in MyFiletoSend.sh:
      - customer/client1/MyFiletoSend.sh
      # Detect any change in the customer folder:
      - customer/client1/*
  script:
      - cd customer/client1
      - delivery.sh

update-client-2:
  stage: update-clients
  only:
    changes:
      - customer/client2/*
  script:
      - cd customer/client2
      - delivery.sh


# repeat for all remaining clients

For more information: https://docs.gitlab.com/ee/ci/yaml/#onlychangesexceptchanges

Related