Search code examples
jenkinscurlgroovyjenkins-pipeline

bat step in Jenkinsfile handles curl command differently when executed directly on the command line


I want to download a tar.gz file using curl and is the command I tried using my Windows' cmd (locally):

curl --user admin:admin --location "https://my_api/doxy_manual.tar.gz" --output doxy_manual.tar.gz 

And this is working since I can open the file if I double-click on it.

Unfortunately if I paste the same exact command within my Jenkinsfile on a running Jenkins instance on a Windows server:

pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                echo 'Hello World'
            }
        }
    }
    
    post {
        always {
            script {
                bat """
                    curl --user admin:admin --location "https://my_api/doxy_manual.tar.gz" --output doxy_manual.tar.gz
                """
            }
        }
    }
}

I get the following error when I double click on the downloaded file:

7-zip: Cannot open file 'C:\Users\john\Downloads\doxy_manual.tar.gz' as archive [gzip]. Error: is not archive

What am I missing?


Solution

  • I added the flag --verbose to the curl command I and figured out that curl was replacing the spaces in my URL with 0 instead of %20 and so I faced Error 404 instead of 200