Search code examples
linuxjenkinsdownloadjenkins-pipelinegzip

How to write a file with Jenkins http_request plugin in gzip format?


In a JenkinsFile, I am trying to recover a gzip compressed file from the url: https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.91.0/pact-1.91.0-linux-x86_64.tar.gz.

With the command

sh 'curl -LO https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.91.0/pact-1.91.0-linux-x86_64.tar.gz'

things work neatly and I can unzip the file etc. However, I need to make this http request via the http_request plugin from Jenkins (doc here: https://plugins.jenkins.io/http_request)

My code follows the Jenkins documentation:

def response = httpRequest url: "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.91.0/pact-1.91.0-linux-x86_64.tar.gz",
                                                httpMode: 'GET'
writeFile file: 'pact-1.91.0-linux-x86_64.tar.gz', text: response.content

The issue is that it does not recognize the file as a gzip compressed data, so I cannot really unzip it via the command tar xzf pact-1.91.0-linux-x86_64.tar.gz.

To check for the file format, I ran the following command in the JenkinsFile:

sh 'file pact-1.91.0-linux-x86_64.tar.gz'

Output: pact-1.91.0-linux-x86_64.tar.gz: data

Output Expected: pact-1.91.0-linux-x86_64.tar.gz: gzip compressed data

I tried to see if I could get the original file and change its format via a linux command, but not sure this is possible. Maybe there is a way either from Jenkins or from Linux to convert this file to a gzip format?


Solution

  • In the end, I was able to find another solution by using the outputFile parameter provided by the Jenkins plugin as the following:

    httpRequest url: "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.91.0/pact-1.91.0-linux-x86_64.tar.gz",
                                                        httpMode: 'GET',
                                                        validResponseCodes: "200"
                                                        outputFile: 'pact-1.91.0-linux-x86_64.tar.gz'