Search code examples
jenkinsgroovyjenkins-agent

Failed to create the file while downloading zip file with CURL on Jenkins slave


I am using Jenkins Pipline and Groovy script to download a zip on slave machine of jenkins.

Following is my code:

pipeline {

    agent { label '<my slave label>' }
    stage('Download') {
            steps {
                script {                
                    def url = "<server url>"
                    def processDownload = ['bash', '-c', "curl -g -k --noproxy \"*\" -o <output-dir> \"${url}\""].execute()
                    processDownload.waitFor()
                    def processUnzip = ['bash', '-c', "7z e lwbs.zip"].execute()
                    processUnzip.waitFor()     
                }      
            }
    }
}

I am getting following error:

Warning: Failed to create the file Warning:

output-dir/newFile.zip: No such file or directory

I have checked following:

  1. When I use the same curl command using command prompt, it run's successfully.
  2. I have also ensured that proper user permissions are granted to allow jenkins to write to this directory.
  3. The directory exists and there are no spaces in the directory url
  4. There is enough disk space available on slave
  5. Server URL and certificates are correct
  6. Many SO but none mentions issue on jenkins slave

Is there anything I am missing?

Any help is appreciated. Thank you.


Solution

  • After long hours of research, I found out the bash command triggered using following command

    def processDownload = ['bash', '-c', "curl -g -k --noproxy \"*\" -o <output-dir> \"${url}\""].execute()
    

    Jenkins will always execute it on Master.

    When I change it to normal shell command, Jenkins is correctly executing it on slave machine. Moreover to unzip, I used Pipeline Utility Steps plugin which provides unzipping functionality which gets executed on slave. Following is my working code:

    stage('Download') {
        steps {
            script {
                url = "<server url>"
                sh "curl -k --noproxy \"*\" -o \"<output-dir>\" \"${url}\""
                unzip(dir: '', glob: '', zipFile: 'fileName.zip')
            }
        }
    }