【问题标题】:Error when push commit to gitlab, pipeline error could not read Username推送提交到 gitlab 时出错,管道错误无法读取用户名
【发布时间】:2021-12-10 23:27:19
【问题描述】:

当我提交对 gitlab 的更改并在 cpanel 上部署项目时。但在管道中出现此错误。 我在这个项目中使用 laravel deployer,我想通过 gitlab 在 cpanel 上部署我的项目。

The command "cd /home/sfd/public_html && (/usr/local/cpanel/3rdparty/lib/pa  
  th-bin/git clone   --recursive  https://gitlab.com/nas-project  
  .git /home/sfd/public_html/releases/1 2>&1)" failed.                         
                                                                               
  Exit Code: 128 (Invalid exit argument)                                       
                                                                               
  Host Name: 51.75.174.102                                                     
                                                                               
  ================                                                             
  Cloning into '/home/sfd/public_html/releases/1'...                           
  fatal: could not read Username for 'https://gitlab.com': No such device or   
  address

我在这里发布我的一些代码,(运行器代码,gitlab-ci.yml,部署代码)

运行器代码

[[runners]]
  name = "DESKTOP-1OOOT34"
  url = "https://gitlab.com/nas-project.git"
  token = "mytoken"
  executor = "shell"
  shell = "powershell"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]

Deploy.php 代码

<?php
return [
    'default' => 'basic',

    'strategies' => [
        //
    ],
    'hooks' => [
        'ready' => [
            'artisan:storage:link',
            'artisan:view:clear',
            'artisan:config:cache',
            'artisan:migrate',
        ],
    ],
    'options' => [
        'application' => env('APP_NAME', 'Laravel'),
        'repository' => 'https://gitlab.com/n1063/suntop/nas-project.git',
    ],
    'hosts' => [
        'mysiteIP' => [
            'deploy_path' => '/home/sfd/public_html',
            'user' => 'sfd',
            'multiplexing' => true,
                'sshOptions'   => [
                    'StrictHostKeyChecking' => 'no',
                    // ...
                  ],
            ],
    ],
    'localhost' => [
        //
    ],
    'include' => [
        //
    ],
    'custom_deployer_file' => false,

];

gitlab-ci.yml

image: edbizarro/gitlab-ci-pipeline-php:7.4

stages:
  - preparation
  - deploy
composer:
  stage: preparation
  script:
    - php -v
    - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts --no-suggest
    - cp .env.example .env
    - php artisan key:generate
  artifacts:
    paths:
      - vendor/
      - .env
    expire_in: 1 days
    when: always
  cache:
    paths:
      - vendor/

yarn:
  stage: preparation
  script:
    - yarn --version
    - yarn install --pure-lockfile
  artifacts:
    paths:
      - node_modules/
    expire_in: 1 days
    when: always


.init_ssh_live: &init_ssh_live |
  mkdir -p ~/.ssh
  echo -e "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
  chmod 600 ~/.ssh/id_rsa
  [[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config

deploy:
  stage: deploy
  script:
    - *init_ssh_live
    - php artisan deploy mySiteIP -s upload
  environment:
    name: live
    url: mySiteIP
  only:
    - dev

【问题讨论】:

  • 使用 https 时,您没有使用 ssh。当您使用https:// URL 时,为什么这会被标记为ssh-keys? (也许这就是整个错误,您应该使用 ssh URL?)
  • @torek 所以我在部署文件中使用 ssh URL 我将 git htts url 放在哪里?
  • 我通常会这样做。生成机器密钥并在机器访问私有存储库时使用它。
  • 你能给我解释一下吗?我从过去 3 天开始就陷入了这个问题。请告诉我我在哪个文件中进行了更改?上面我提到了 2 个文件及其代码(deploy.php | gitlab-ci.yml)。请帮助我@torek
  • 我从来没有使用过 GitLab 的管道和 CI 系统,所以我不知道那里的任何细节。但一般来说,当您有一些机器用户(构建软件)克隆存储库时,它不会代表某些 user 运行,因此没有可用的用户名或用户密钥。因此,您使用ssh://git@&lt;host&gt;/path/to/repo.git URL 并确保 this ssh 命令在设置$HOME/.ssh/ 的情况下运行,以便它发送一个授权从给定主机读取 URL 的 ssh 密钥。

标签: laravel git gitlab ssh-keys cicd


【解决方案1】:

如果你想通过 GitLab 在 cPanel 服务器上部署 Laravel 项目而不需要任何包,那么这可能会对你有所帮助。配置细节在描述https://gitlab.com/-/snippets/2238596

【讨论】:

  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
猜你喜欢
  • 2023-04-08
  • 1970-01-01
  • 1970-01-01
  • 2018-06-16
  • 2020-03-04
  • 1970-01-01
  • 2020-07-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多