Home > OS >  How to know if an artifact already exists in Jfrog Artifactory by Jenkins
How to know if an artifact already exists in Jfrog Artifactory by Jenkins

Time:10-20

I'm developing a Jenkins declarative pipeline. I have the version as a parameter and depending on that version I would like to know if a specific folder exists in Jfrog Artifactory before downloading it. I have Jenkins Artifactory Plug-in installed. Is there a way I can know this information before downloading it?

Edit: I realized that my question was a bit out of context. In the end what I want to do is to upload an artifact. But in case the artifact already exists, I would like to give a warning to the user if he wants to proceed. And I was wondering if there was a solution, different than downloading an artifact to see if it exists, giving a warning depending if it was a successful download, and after that uploading the artifact.

CodePudding user response:

You can use the jfrog rt s JFrog CLI command to search files in Artifactory.

Adding the --count to the command, counts the total of items found in Artifactory under the specified path. For example, suppose you wish to check if a file named f.zip exists in the generic-local repository, under the a/b/ path, run the following command

jfrog rt s generic-local/a/b/f.zip --count

The output will probably be

[Info] Searching artifacts...
[Info] Found 0 artifacts.
0

Notice that it returned 0 in the above example. If the file existed, it would have returned 1. Since only the last output line is sent to stdout, you can pick it up by, for example, writing it to a file.

CodePudding user response:

An option would be to use curl as if you were to download the file. But instead of raising a GET request, just run a HEAD request.

curl -X HEAD ...

curl --head ...

The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself. https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

  • Related