【问题标题】:Conditional path to deploy in cpanel.yml file configuration在 cpanel.yml 文件配置中部署的条件路径
【发布时间】:2021-02-06 22:21:44
【问题描述】:

我需要根据这个文件的当前路径将同一个仓库部署在不同的路径

示例:

如果这个 .Cpanel.yml 在位于 "/home/foo/repository/foo_prod/" 的存储库中,则在 /home/ 中实现它foo/public_html/production_folder/ 但如果是文件位置 binder 。 cpanel.yml"/home/foo/repository/foo_pre_prod/"所以实现在/home/foo/public_html/pre_prod_folder/


当前文件 .cpanel.yml

---
deployment:
  tasks:
    - export DEPLOYPATH=/home/foo/public_html/xyz/
    - /bin/cp -R * $DEPLOYPATH 

【问题讨论】:

    标签: linux bash deployment path repository


    【解决方案1】:

    不妨试试这样的:

    deployment:
      tasks:
        - current_branch=$(git branch --show-current) # set current branch to variable
        - if [ $current_branch == "master" ]; then export DEPLOYPATH=/home/foo/public_html/xyz/; fi;
        - if [ $current_branch == "develop" ]; then export DEPLOYPATH=/home/foo/public_html/xyz_dev/; fi;
        - /bin/cp -R * $DEPLOYPATH
    

    【讨论】:

    • 谢谢。引导我找到解决方案,但是 $(git branch --show-current) 正在返回 error: unknown option 'show-current'... 所以我最终使用了 $(git rev-parse --abbrev-ref HEAD),它工作得很好。
    • 我尝试了这两种方法,但我得到了error: unknown option show-current'` ps:对于其他想知道的人:您可以在 /home/username/.cpanel/logs/vc_* 中访问您的日志_git_deploy.log - 打开最新的日志。
    • 谢谢@Salines,我会看看这些。我的托管服务提供商的支持人员指出我为此目的使用 /home/username/repositoryFolder/.git/hooks/post-receive git hook(用于 cPanel),我会先试一试。
    • 在 post-receive 挂钩中获取分支名称的唯一方法是 branch=$(echo $ref | awk -F / '{ print $(NF) }')
    【解决方案2】:

    解决了我之前的问题!我分享我所做的。谢谢@Salines 你的 请帮助我!

    ---
    deployment:
    tasks:
    - current_path=`pwd` # set current path to variable
    - if [ $current_path == "/home/user/repositories/p" ]; then export DEPLOYPATH=/home/user/public_html/p/; fi;
    - if [ $current_path == "/home/user/repositories/p_pre" ]; then export DEPLOYPATH=/home/user/public_html/p_pre/; fi;
    - /bin/cp -R * $DEPLOYPATH
    

    【讨论】:

      猜你喜欢
      • 2019-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-26
      • 1970-01-01
      相关资源
      最近更新 更多