hello rac ...@
Rundeck is running on linux debian 11 server :
- Linux node : working cool with Ansible, all good.
- Managing Windows remote Node (WinRM cerdssp etc) .... just weird things
i'm trying to integrated Robocopy in powershell code for Rundeck (please note that this was done before with Planned sheduled task of windows).
That's is an inline script based job? : no, "Script file or URL - Execute a local script file or a script from a URL"
Or you're calling a script from
the command step? no from Script File, defined with two args and file extension .ps1
Could you share a basic reproducible example to test?
Node def. (srvfile1 is the node where we launch robocopy to hunded synlogy NAS , smb share etc):
<node name="srvfiler1 description="Serveur Fichiers" tags="filer" osFamily="windows" osArch="amd64" osName="Windows Server 2016 Standard" hostname="srvfile1" username="svcrundecknode" file-copier-add-utf8-bom="true"/>
Node step :
<command>
<description>srv1 POWERSHELL (script file)</description>
<fileExtension>ps1</fileExtension>
<scriptargs>'\\srv1\Modèles de documents'
'\\nassyno1\AMC-FRANCE\Modèles de documents"'</scriptargs>
<scriptfile>/var/lib/rundeck/projects/AD/scripts/robocopy-rundeck-v2.ps1</scriptfile>
</command>
i'm stucking with this code , i can't achieve to have exit code working in Rundeck : $lastexitcode is always 0 ... so always succes !!!
But robocopy is doing the job : this is weird.
Rundeck version? the laste one 3.4.5,
You're using the
pywinrm plugin to connect to a windows node? yes, buitl in .WinrRM node executor Python.
New : Code
# Arguments
$SourceUNC=$args[0]
$DestinationUNC=$args[1]
# Constant
$Command="C:\Windows\system32\robocopy.exe"
$Arguments=@("/MIR","/NFL","/NDL","/nc","/ns","/np","/R:2","/W:3")
$RundeckLogPath="C:\Rundeck\Log"
# log
New-Item -ItemType Directory -Force -Path $RundeckLogPath |Out-Null
$DestURI=New-Object System.Uri($DestinationUNC)
$DestHost=$DestURI.Host
$LogFile="$RundeckLogPath\Robocopy-$DestHost.log"
# Display for Rundeck
Write-Host "$Command ""$SourceUNC"" ""$DestinationUNC"" $Arguments"
# Running
$LastExitCode=0
#& $Command "$SourceUNC" "$DestinationUNC" $Arguments /LOG:$LogFile
robocopy.exe "$SourceUNC" "$DestinationUNC" $Arguments /LOG:$LogFile
$CommandRetCode=$LastExitCode
# Erro management
if ($CommandRetCode -gt 7)
{
Write-Host "Robocopy failed with exit code: " $CommandRetCode
write-Host "See : https://ss64.com/nt/robocopy-exit.html"
exit $CommandRetCode
}
else
{
Write-Host "Robocopy Ok: " $CommandRetCode #=====>>>> here we have a problem , always returning 0 ...even exitcode is 0 , 1 or 2 or 3 !!!
exit 0
}