首页 文章

使用Vue在Gitlab中配置gitlab-ci.yml文件

提问于
浏览
1

尝试使用带有GitJ的CI和CD与Gitlab .

使用50种不同的gitlab-ci.yml配置,并在不同阶段保持大量问题 .

我按照以下教程来了解T:

https://about.gitlab.com/2017/09/12/vuejs-app-gitlab/

build site:
  image: node:6
  stage: build
  script:
    - npm install --progress=false
    - npm run build
  artifacts:
    expire_in: 1 week
    paths:
      - dist

deploy:
  image: alpine
  stage: deploy
  script:
    - apk add --no-cache rsync openssh
    - mkdir -p ~/.ssh
    - echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_dsa
    - chmod 600 ~/.ssh/id_dsa
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
    - rsync -rav --delete dist/ user@server.com

我跳过了测试阶段,因为它一直在失败...所以为什么不跳过它 .

如果它有帮助,使用此配置,我不断收到以下错误:
enter image description here

你的gitlab-ci.yml文件(适用于VueJS webapp)是什么样的?

1 回答

  • 1

    昨天我在研究如何在Gitlab上设置CI / CD时碰到了这个问题 . 经过24小时的研究和测试 . 我终于得到了一个工作脚本 . 希望这可以帮助 .

    为此,您需要:

    • 在项目的 Settings -> Variables 部分中设置变量 STAGING_PRIVATE_KEY

    • 将ssh密钥添加到服务器上的已知主机列表中

    以下是我的最终脚本:

    image: node:latest
    
    stages:
      - build
      - deploy
    
    build site:
      stage: build
      before_script:
        - apt-get update
        - apt-get install zip unzip nodejs npm -y
        - npm install --progress=false
      cache:
        paths:
        - node_modules/
      script:
        - npm run build
      artifacts:
        expire_in: 1 week
        paths:
          - dist/
    
    deploy:
      stage: deploy
      before_script:
        - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
        - eval $(ssh-agent -s)
        - echo "$STAGING_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
        - mkdir -p ~/.ssh
        - chmod 700 ~/.ssh
        - ssh-keyscan YOUR-SEVER-IP >> ~/.ssh/known_hosts
        - chmod 644 ~/.ssh/known_hosts
      script:
        - ssh -p22 root@YOUR-SEVER-IP "mkdir /var/www/_tmp"
        - scp -p22 -r /builds/YOUR-USERNAME/YOUR-REPO-TITLE/dist/* root@form.toprecng.org:/var/www/form.toprecng.org/_tmp
        - ssh -p22 root@YOUR-SEVER-IP "mv /var/www/html/ /var/www/_old && mv /var/www/_tmp /var/www/html/"
        - ssh -p22 root@YOUR-SEVER-IP "rm -rf /var/www/_old"
    

相关问题