How to stop robocopy from exiting the build?

时间:2017-06-12 16:53:42

标签: gitlab-ci gitlab-ci-runner

I'm using Gitlab 8.15.4 and the latest runner for that build. Because of our firewall I can't run npm install so I'm copying the node-modules from another location into the build folder. The runner is on a Windows 7 machine.

My first attempt: (.gitlab-ci.yml)

before_script:
- robocopy S:\Storage\GitLab-Runner\Assets\node_modules .\node_modules /s
build:
  stage: build
  script:
    - echo starting
    - gulp
    - echo done
  artifacts:
    paths:
    - deploy.zip   

Fails the build with the error:

ERROR: Job failed: exit status 1

My second (nth) try puts the robocopy into a script file and executes it from there:

(.gitlab-ci.yml)

before_script:
- S:\Storage\GitLab-Runner\Scripts\CopyAssets.bat
build:
  stage: build
  script:
    - echo starting
    - gulp
    - echo done
  artifacts:
    paths:
    - deploy.zip   

(CopyAssets.bat)

robocopy S:\Storage\GitLab-Runner\Assets\node_modules .\node_modules /s
set/A errlev="%ERRORLEVEL% & 24"
exit/B %errlev%     

Passes but does not execute any other steps.

How can I prevent RoboCopy from exiting the build when it finishes?

2 个答案:

答案 0 :(得分:7)

您和许多其他人在CI部署中遇到了robocopy的问题。由于我发现这个问题在一段时间内没有得到答复,而其他答案与robocopy之后继续使用脚本不兼容,我想在这里分享解决方案。

如果您希望robocopy忽略8下的所有返回代码(> = 8表示复制错误),则需要一个直接遵循命令的条件并更改错误级别。

INSERT INTO cil.schedule (taskFK, scheduledDate, rotaCycle) 
SELECT taskFK, scheduledDate = DATEADD(dd, (SELECT rotaCycle FROM 
cil.schedule WHERE id=??),scheduledDate), rotaCycle
FROM cil.schedule LEFT JOIN cil.task ON task.id=schedule.taskFK
WHERE completionDate=@myCompletionDate
AND task.equipFK=@equipID;

答案 1 :(得分:0)

对于 PowerShell 用户:

(robocopy src dst) ; if ($lastexitcode -lt 8) { $global:LASTEXITCODE = $null }

cmd /c (robocopy src dst) ^& IF %ERRORLEVEL% LEQ 1 exit 0

我已经使用 GitLab Runner powershell 在 GitLab 13.12 上进行了测试,并且运行良好。