0

I have a requirement where i have to check if artifact version is already present or nexus or not. if already present then fail the build else proceed with the deployment.

I tried this curl command to fetch.. but i'm getting error

curl -s -k --user ${credentials} \"${nexusHost}/service/local/artifact/maven/content?r=${repository}&g=${groupId}&a=${artifactId}&v=${version}&p=${packaging}\" -o ${fileName} &> /dev/null

where repository i'm giving "snapshots" .

But this is throwing error. Please help me out here

garima
  • 53
  • 1
  • 9
  • What's the error you're getting? Also, if you can access the artifactory through the browser, why not try `curl` command directly on that url? For example: org.apache.commons:common-lang3:3.10 is available, but 3.11 is not. So [3.10](https://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.10) works but [3.11](https://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.11) doesn't. – kayvis May 12 '20 at 12:17
  • I am getting below error Error 404 Not Found

    HTTP ERROR: 404

    Problem accessing /service/rest/beta/search/assets. Reason:

        Not Found

    Powered by Jetty://
    – garima May 12 '20 at 12:27
  • Are you allowed to access the artifactory through your browser? If so, we can use that url to determine if the artifact is already in the artifactory. I've given two same urls, one works and one doesn't. Since you already know the version you're looking for, we can construct a url and try `curl` to that url and intercept the http `status code` and determine if it's already present. If that's okay, I can give you the script to intercept the status code. – kayvis May 12 '20 at 12:30
  • 1
    If the artifact is a SNAPSHOT it does not make sense. If it is a release any deployment with Maven will fail...I don't see really the benefit of this? – khmarbaise May 12 '20 at 15:34

1 Answers1

1

Thanks all for the help..

I got this URL which gives all the details related to given g:a:v values. And most importantly it gives the total count also, which was useful in my case.

curl -u $USERNAME:$USERPASS "https://${host}:8081/nexus/service/local/lucene/search?g=${pomGroup}&a=${pomArtifact}&v=${pomVersion}*"

garima
  • 53
  • 1
  • 9