简体   繁体   中英

Jenkins check file exists inside zip file

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

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

PS If zip contains directory structure, then grep with full path of the file name

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM