Sunday, September 4, 2022

[SOLVED] Jenkins check file exists inside zip file

Issue

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


Solution

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"


Answered By - Gajapathi Kimidi
Answer Checked By - Candace Johnson (WPSolving Volunteer)