Why does my gitlab pipeline fail with rsync error

Viewed 411

I used the pipeline in a another project and here it worked.
But now I have a problem (I'm using exactly the same settings)

staging_upload:
  stage: staging
  only:
    refs:
      - develop
      - schedules
  script:
    - sshpass -e rsync -avz --progress --exclude='.git' --exclude='.gitlab-ci.yml' . $SSH_USERNAME@j$HOST:/home/xy/html/project/staging/

Now I get this error:

rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(644) [sender=3.1.2]

Has anyone a clue what is going wrong here?

2 Answers

sshpass is very rarely used in gitlab-ci.yml files.
Much more frequent is the use of an ssh-agent (if your private key is passphrase-protected), as seen here.

before_script:
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
  - 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
  - eval $(ssh-agent -s)
  - ssh-add <(echo "$SSH_PRIVATE_KEY_DEV")
  - ssh-add <(echo "$SSH_PRIVATE_KEY_PROD")
  - mkdir -p ~/.ssh
  - '[[ -f /.dockerenv ]] && echo "$SSH_HOSTKEYS" > ~/.ssh/known_hosts'

dev:
  script:
    - rsync --exclude=.gitlab-ci.yml --exclude=.git -avx -e ssh `pwd`/ dbasdev@iaas.ouce.ox.ac.uk:/var/www/html/it_dev/it_monitor_app/auth/

Check if this approach is more reliable, using a masked variable for your private key.

Try running the script with a -v (or 2). The verbose output will show you where/why it is stalling. Also, validate your escaped characters and absolute paths. They are fairly common reasons for rsync to stall.

Related