GITLAB-CI:使用GIT进行现场部署

时间:2020-07-17 03:50:02

标签: git gitlab-ci

我在这里试图了解CICD出了什么问题。

上下文:

  • 源代码托管在私人GITLAB projet中
  • Web应用(laravel / php)由GANDI托管(简单托管)
  • 通过simplehosting提供,可以deploy application using GIT

我的目标是管理cicd管道(使用gitlab-ci)以检查代码质量,运行单元测试并在测试/阶段环境中自动部署。然后通过手动操作将其部署到生产中。

我的问题是处于部署阶段:如何将我的gitlab存储库推送(部署)到托管git?

我最初的担心是没有什么可推动的(从我的跑步者/图像中查看)。 我遇到了src refspec错误。

$ git push gandi master
error: src refspec master does not match any.
error: failed to push some refs to 'git+ssh://xxx@git.sd6.gpaas.net/test.domain.tl.git'
ERROR: Job failed: exit code 1

我在HEAD:中使用git push选项尝试了4181861中提出的解决方案。
还有Job succeeded
但是... 托管服务器上没有更新

我了解没有任何更新可推动跑步者的观点。

$ git status
HEAD detached at ff1ce8c
nothing to commit, working tree clean

那该怎么办?
我正在寻找新的探索途径。


我的gitlab-ci.yml

image: php:latest

before_script:
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
  - mkdir -p ~/.ssh
  - eval $(ssh-agent -s)
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  - ssh-add <(echo "$SSH_PRIVATE_KEY")

stages:
  - deploy

job_deploy_staging:
  stage: deploy
  script:
    - echo "Deploy the app into (gandi) staging environnement"
    - git config --global user.email "$GIT_EMAIL" && git config --global user.name "$GIT_NAME"
    - git remote add gandi git+ssh://$GANDI_USER@$GANDI_GITSERVER/$GANDI_GITREPO_TEST
    - git status
    - git show
    - git push gandi HEAD:master
  environment:
    name: staging
    url : http://test.domain.tl
  only:
    - master


job_deploy_prod:
  stage: deploy
  script:
    - echo "Deploy the app into (gandi) production environnement"
    - git config --global user.email "$GIT_EMAIL" && git config --global user.name "$GIT_NAME"
    - git remote add gandi git+ssh://$GANDI_USER@$GANDI_GITSERVER/$GANDI_GITREPO_PROD
    - git push gandi master
  environment:
    name: production
    url : http://www.domain.tl
  when: manual
  only:
    - master

0 个答案:

没有答案