jenkins: failed to access to the workspace from Groovy libraries on a Windows agent

64 Views Asked by At

I'm running a pipeline on a Jenkins agent running on Windows Server 2016, this pipeline is using a Jenkins library to download file from local server. The download is done with a method using curl and the java class ProcessBuilder.

    /**
    * not for direct use
    * download to nexus the webapplication, by running Curl command
    */
    def download(String user_password, String filename, String folder, Boolean isTestData = false) {

        def nexus_url = this.getNexusFolder(isTestData) + "/" + filename
        def curl_cmd = 'curl'
        if (this.curlPath != null){
            curl_cmd = this.curlPath
        }
        def target_folder = new File(folder)
        if (!target_folder.exists()){
            this.script.echo("The folder |$folder| not exists. Failed to download")
            return false
        }
        def pBuilder  = new ProcessBuilder(curl_cmd, '-v', '-O', '-u', user_password, nexus_url )
        pBuilder.redirectErrorStream(true)
        pBuilder.directory(target_folder)
        def curl_process = pBuilder.start()
        this.script.echo(curl_process.getInputStream().getText())
        curl_process.waitForOrKill( this.curlTimeout )
        if (  curl_process.exitValue() != 0 ) {
            println String.format('Warning exit code: %s', curl_process.exitValue().toString())
            return false
        }
        this.script.echo("download of $nexus_url is finished in folder $folder")
        return true
    }

On one agent (and not on the controller), this code failed because the exists function says that the folder doesn't exist! Of course this folder exists as it the workspace. See below the amazing output (the pipe has been added to check there is no special character in the string).

enter image description here

I try to check if it's sandbox issue by running the same code from Jenkins console of the slave. Tests are not conclusive because one time I reproduced the error, and one time is has worked. If I removed the test of the folder existence, the curl command refuses to start: java.io.IOException: Cannot run program "curl" (in directory "d:\jenkins\workspace\WSM\IN_PROGRESS\WSM_VALIDATION_BUILD"): CreateProcess error=267, The directory name is invalid

Is there any special behavior of the groovy sandbox that could explain this error? Do you have:

  • an explanation of this behavior
  • an idea or a test to find the origin of the problem
0

There are 0 best solutions below