gitlab ci管道失败部署ftp

时间:2020-03-01 15:48:08

标签: gitlab

我尝试使用gitlab-ci.yml构建并推送我的react build文件夹 构建并测试通过,但部署失败,并出现以下错误: 如果我在语言环境文件中执行相同的脚本,则可以正常工作!

    lftp -e "mirror -R build/ ./test ; quit" -u $USERNAME,$PASSWORD $HOST
mirror: Access failed: /builds/myGitLab/myGitlabProjectName/build: No such file or directory
lftp: MirrorJob.cc:242: void MirrorJob::JobFinished(Job*): Assertion `transfer_count>0' failed.
/bin/bash: line 97:   275 Aborted                 (core dumped) lftp -e "mirror -R build/ ./test ; quit" -u $USERNAME,$PASSWORD $HOST
ERROR: Job failed: exit code 1

这是我所有的yml文件:

image: node:13.8

stages:
  - build
  - test
  - deploy

build:
  stage: build
  script:
    - npm install
    - npm run build

test:
  stage: test
  script:
    - yarn
    - yarn test

deploy:
  script:
    - apt-get update && apt-get install -y lftp
    - lftp -e "mirror -R build/ ./test ; quit" -u $USERNAME,$PASSWORD $HOST
    
enter code here

2 个答案:

答案 0 :(得分:0)

我知道了!我从docker映像(节点)开始执行这三个阶段:构建,测试和部署,但是没有成功,但是我尝试在阶段部署中执行ls-a,我意识到我没有构建文件夹。因为docker映像是每次都重新创建的,所以我添加了工件以保留buid文件! 一旦构建阶段的工作“完成”。它就保留了对下一个工作可读的变量buid以及部署!

image: node:13.8

stages:
  - build
  - test
  - deploy

build:
  stage: build
  script:
    - npm install
    - npm run build
  only:
    - master
  artifacts:
    paths:
      - build

test:
  stage: test
  script:
    - yarn
    - yarn test

deploy:
  stage: deploy
  before_script:
    - apt-get update -qq
  script:
    - apt-get install -y -qq lftp
    - ls -a
    - lftp -e "set ssl:verify-certificate false; mirror --reverse --verbose --delete build/ ./test2 ; quit" -u $USERNAME,$PASSWORD $HOST
  only:
    - master

答案 1 :(得分:-1)

我有部分答案,但我想做得更好 实际上,我了解发生了什么。在每个阶段构建docker映像之后,再进行测试和部署之后,便不再存在构建文件夹。 我不知道如何让泊坞窗映像成为每个阶段的节点。 任何帮助都将受到欢迎。 为了使它起作用,我以这种方式在一个阶段中完成了每个脚本: image: node:13.0.1

stages: - production

build: stage: production script: - npm install - npm run build - npm run test - apt-get update -qq && apt-get install -y -qq lftp - lftp -e "mirror -R build/ ./test ; quit" -u $USERNAME,$PASSWORD $HOST only: - master