Search code examples
batch-filecmdjenkins-pipelinetarwindows-server-2019

How to tar folder on windows server 2019


I have the below path in my jenkins worksapce:

Report Services\bin\Release\

How can I tar this folder from Jenkinsfile (the command runs against windows server 2019 server)? Per my understating, tar.exe and curl.exe were first included with Windows Server 2019.

I tried the below in my Jenkinsfile:

bat "tar -cvzf output.tar.gz Report Services\\bin\\Release"

but I keep getting error of:

tar: Report: Couldn't find file: No such file or directory
tar: Services/bin/Release: Couldn't find file: No such file or directory

In addition, to improve it, how can I tar only the *.rdl files from this directory?


Solution

  • You need to escape " and \ replaced with \\ : Please see below example:

    bat "tar -cvzf output.tar.gz \"Report Services\\bin\\Release\""
    

    If you want to tar certain files :

    bat "tar -cvzf output.tar.gz \"Report Services\\bin\\Release\\*.rdl\""