I am at ground zero for using/learning Gitlab CI. As such I am trying to come up with a basic workflow of getting a batch of PowerShell scripts we have sitting on a server into version control. The workflow is meant to be as basic as it gets–if a script is added/updated/removed in the repo I want it to be reflected on the server in question. There is no build or test phase.
To this end I have a shell runner set up on a Windows Server. When I call the PowerShell commands in the gitlab-ci.yml it works as expected. If the gitlab-ci.yml instead calls a PS script with the same commands I get some errors I do not understand about files that cannot be overwritten in the build directory.
Copy-Item : Cannot overwrite the item C:\GitLab-Runner\builds\EkMFgxya\0\duit-acso\test-utility-server-scripts-\Scripts \Powershell\ResetAdminPasswords\WASP\UnInstall.ps1 with itself. At C:\GitLab-Runner\builds\EkMFgxya\0\duit-acso\test-utility-server-scripts-\copyFiles.ps1:22 char:1 + Copy-Item -Recurse -Path Scripts -Destination "FilesDestination:" -Fo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (C:\GitLab-Runne...P\UnInstall.ps1:String) [Copy-Item], IOException + FullyQualifiedErrorId : CopyError,Microsoft.PowerShell.Commands.CopyItemCommand
Being new to this I was working on the assumption the build folder could be overwritten as needed. I have the force flag set on the Copy-Item command (though I would think this does ont apply to what is going on in build, just he copy to the remote server)
The yaml is like this:
stages: - deploy Copy_Files: stage: deploy tags: - windows - shell script: # run PowerShell script # - ./copyFiles.ps1 -DestinationPath "\\<Server Name redacted>\c$" - New-PSDrive -Name "FilesDestination" -PSProvider FileSystem -Root "\<Server Name redacted>\c$" - Copy-Item -Recurse -Path Scripts -Destination "FilesDestination:" -Force -Confirm:$False only: - master
The commented out bit is what is failing, below that are the commands that work.