Home > other >  Jenkins check file exists inside zip file
Jenkins check file exists inside zip file

Time:06-07

is there a way to check a file exists inside a zip file without unzip it. I'm using Artifactory . if use curl can't. can advice me,

I tried below

 sh(script: "curl -o /dev/null -sf <antifactory url>")

this always return success andbelow

unzip -l <file.zip> | grep -q <file name>

this need install unzip

CodePudding user response:

You can make use of bash commands unzip and grep.

unzip -l my_file.zip | grep -q file_to_search

# Example 
$ unzip -l 99bottles.zip | grep -q 99bottles.pdf && echo $?
0

P.S. If zip contains directory structure, then grep with full path of the file name

CodePudding user response:

From Artifactory 7.15.3 as mentioned in this page archive search is disabled by default. Can you confirm if you are version above this. If yes, you can enable this feature by Navigating to Admin > Artifactory > Archive Search Enabled and enable this checkbox. But please be aware that, if we enable this feature, it keeps writing a lot of information to the database for every archive file and can impact the performance.

Later you can search items in a zip file. Below is an example command where I am searching for .class files in my zip from curl. You may opt similar to this in Jenkis.

$ curl -uadmin:password -X GET "http://localhost:8082/artifactory/api/search/archive?name=*.class&repos=test" -H "Content-type: application/json"
  • Related