简体   繁体   English

将rsync与gitlab-ci.yml一起使用以同步Wordpress主题文件夹

[英]Use rsync with gitlab-ci.yml to sync Wordpress theme folders

While trying to use .gitlab-ci.yml to automatically deploy my theme to my production server, I receive a error: 尝试使用.gitlab-ci.yml将主题自动部署到生产服务器时,收到错误消息:

The command executed: using a ubuntu:16.04 image 执行的命令:使用ubuntu:16.04图片

$ apt update -y && apt install openssh-client sshpass rsync -y
$ rsync -avh --progress --delete --rsh="sshpass -p $STAGE_FTP_PASS ssh -o StrictHostKeyChecking=no " --exclude=.git ./ $STAGE_FTP_USER@my.wp.address/project-folder/wp-content/themes/sg-coesfeld-theme/

The error result: 错误结果:

sshpass: invalid option -- 'o'
protocol version mismatch -- is your shell clean?
(see the rsync man page for an explanation)
rsync error: protocol incompatibility (code 2) at compat.c(176) [sender=3.1.1]
ERROR: Job failed: exit code 1

I am using the exact same .gitlab-ci.yml , server, FTP account, runner and gitlab hosting successfully to auto-deploy in other git repos. 我正在使用完全相同的.gitlab-ci.yml ,服务器,FTP帐户,运行程序和gitlab托管成功地在其他git仓库中自动部署。

The only thing that has changed is the source git repository and the /project-folder/ . 唯一更改的是源git存储库和/project-folder/

To be honest I do not know where to start and how to track down this issue, so I am happy about any suggestions. 老实说,我不知道从哪里开始以及如何追踪这个问题,所以我对任何建议都很满意。

Your $STAGE_FTP_PASS must be empty so the command would become 您的$STAGE_FTP_PASS必须为空,这样命令将变为

sshpass -p ssh -o StrictHostKeyChecking=no 

so sshpass would think -p ssh is the password and -o StrictHostKeyChecking=no is the command. 因此sshpass会认为-p ssh是密码,而-o StrictHostKeyChecking=no是命令。

As @pynexj already has said, $STAGE_FTP_PASS was an empty string, which caused the error. 正如@pynexj已经说过的, $STAGE_FTP_PASS是一个空字符串,这导致了错误。 I have tried this using echo $STAGE_FTP_USER inside my script. 我已经在脚本中使用echo $STAGE_FTP_USER进行了尝试。

While inserting the secret variables, I have checked the box [X] Protected , which has an explanation attached: This variable will be passed only to pipelines running on protected branches and tags. 插入机密变量时,我已选中[X] Protected框,该框附带说明: 此变量将仅传递给在受保护的分支和标签上运行的管道。

Searching for protected branches I have noticed, that in Settings > Repository > Protected Branches no protected branch was set. 搜索我注意到的受保护分支 ,在“设置”>“存储库”>“受保护分支”中未设置受保护分支。

So I could choose between unchecking the [ ] Protected checkbox, so that every branch can use the secret variables, or go with the more secure approach and add my branch (for example master ) as a protected branch. 因此,我可以在取消选中[ ] Protected复选框之间进行选择,以便每个分支都可以使用秘密变量,或者采用更安全的方法并将我的分支(例如master )添加为受保护的分支。

Now everything works great again. 现在,一切再次恢复正常。 Thanks again to @pynexj for pointing out what causes the problem in the script. 再次感谢@pynexj指出导致脚本问题的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM