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?
You and a lot of other people have encountered this issue with robocopy in CI deployment. As I have found this question being unanswered for some time and the other answers being incompatible with continuing the script after robocopy, I want to share the solution here.
If you want robocopy to ignore all return codes under 8 (>= 8 means copy error), you need a condition that follows the command directly and changes the error level.
(robocopy src dst) ^& IF %ERRORLEVEL% LSS 8 SET ERRORLEVEL = 0
For powershell users:
(robocopy src dst) ; if ($lastexitcode -lt 8) { $global:LASTEXITCODE = $null }
or
cmd /c (robocopy src dst) ^& IF %ERRORLEVEL% LEQ 1 exit 0
I have tested on GitLab 13.12 with GitLab Runner powershell and it worked well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With