Error at the end of PIPELINE

Good morning guys!
I have the script below:

pipeline {
agent any
stages {
stage(‘Backup_Copia’) {
steps {
script {
def sourceDir = ‘\\HECP162\corporativoteste’
def destDir = ‘\\HECP162\temp’

                // Usar o comando 'robocopy' para comparar e copiar arquivos
                bat "robocopy ${sourceDir} ${destDir} /MIR /XO /XF *.ari *.cs *.rsp *.ver *.0* *.002 *.log *.yaml *.csv *.info *.bld *.00* *.web *.data *.svc *.apk"
            }
        }
    }
    stage('PC510_HECP162') {
        steps {
            script {
                def sourceDir = '\\\\PC510\\web'
                def destDir = '\\\\HECP162\\corporativojenkins'

                // Usar o comando 'robocopy' para comparar e copiar arquivos
                bat "robocopy ${sourceDir} ${destDir} /MIR /XO /XF *.ari *.cs *.rsp *.ver *.0* *.002 *.log *.yaml *.csv *.info *.bld *.00* *.web *.data *.svc *.apk"
            }
        }
    }        
    stage('Mensagem_Copia') {
        steps {
            script {
                echo "Arquivos copiados com sucesso!"
            }
        }
    }
}
post {
    success {
        echo "Pipeline concluído com sucesso!"
    }
    failure {
        echo "Ocorreu um erro no pipeline."
    }
}

}

At the end of execution it displays an error, but does not display the error at the end of the log.

The objective of this script is to take an official folder, save it in a temporary folder and then take the changed code and publish it in the official folder.
In the script I’m putting together, it makes the comparison and copies the newest files and eliminates some extensions.

If there are new files at the time of copying, it carries out the process and displays the error, if there is nothing to copy, it does not display the error.

From your perspective, is there a syntax problem in the script?
Is there another way to do this?

Thank you very much

#Genexus Using Jenkins pipeline windows

Does robocopy return a 0 exit code? If not, then Jenkins will consider it a failure. If it does not, you will need to handle that in your bat call.

Hello Alex!
I’m just starting out in the world of scripts.
I have no idea what value it is returning, could you tell me how I capture this error code?
Thank you very much

Robocopy returns error code 0 only when it copied no files, When some where copied/skipped it will return an error code > 0

Hello Markus!
I’m going to search the web for how to recover this robocopy error code.
Thank you very much

From Return codes used by the Robocopy utility - Windows Server | Microsoft Learn

0 No files were copied. No failure was met. No files were mismatched. The files already exist in the destination directory; so the copy operation was skipped.
1 All files were copied successfully.
2 There are some additional files in the destination directory that aren’t present in the source directory. No files were copied.
3 Some files were copied. Additional files were present. No failure was met.
5 Some files were copied. Some files were mismatched. No failure was met.
6 Additional files and mismatched files exist. No files were copied and no failures were met. Which means that the files already exist in the destination directory.
7 Files were copied, a file mismatch was present, and additional files were present.
8 Several files didn’t copy.
1 Like

In a bat file (or cmd.exe in general) you can get the exit code for the last command with the %ERRORLEVEL% environment variable.

Thank you very much Markus!

Thank you very much Alex!

Thank you very much
I solved it with the following code:

// Executar o comando ‘robocopy’ e armazenar o código de saída
def robocopyExitCode = bat(script: “robocopy {sourceDir} {destDir} /MIR /XO /XF *.ari *.cs *.rsp *.ver .0 *.002 *.log *.yaml *.csv *.info *.bld .00 *.web *.data *.svc *.apk || 0”, returnStatus: true)

if (robocopyExitCode == 1) {
echo “Código de saída do robocopy: ${robocopyExitCode}”
}
echo “A comparação foi concluída.”