简体   繁体   中英

Build Upload using Artifactory REST API

I am having trouble figuring out how to register an already uploaded artifact to the artifactory build. I know that I can use the artifactory build upload endpoint which is partly working for me but just can't figure out the correct payload to use for the JSON data.

I have tried using different payload referring to the information I see under the artifact information.

This is my payload:

{
    "url":  "https://bamboo-ci-server-url/browse/EC-SRT0-25",
    "vcsRevision":  "14fc6dcf71bee74e328078",
    "artifactoryPrincipal":  "username",
    "version":  "4.0.0-SNAPSHOT",
    "number":  "27",
    "started":  "2019-11-04T19:49:35.471+0100",
    "name":  "SPO3.MGUI.RTEST",
    "properties":  {
                       "buildInfo.env.JAVA_HOME":  "java_home"
                   },
    "issues":  {
                   "tracker":  {
                                   "version":  "8.5.0",
                                   "name":  "JIRA"
                               },
                   "affectedIssues":  [
                                          {
                                              "url":  "https://jira-url/browse/projectkey-3433",
                                              "key":  "projectkey-3433",
                                              "summary":  "Testing snapshot builds automation"
                                          },
                                          {
                                              "url":  "https://bamboo-ci-cerver-url/browse/EC-3408",
                                              "key":  "projectkey-3408",
                                              "summary":  "Create release for 1.4"
                                          }
                                      ]
               },
    "modules":  [
                    {
                        "id":  "SPO3.MGUI.RTEST-4.0.0-SNAPSHOT",
                        "artifacts":  [
                                          {
                                              "name":  "/com/company/module/SPO3.MGUI.RTEST/4.0.0-SNAPSHOT/ivy.xml",
                                              "md5":  "a242c427c6c1fdcd33c1c0498fb41324",
                                              "type":  "application/xml",
                                              "sha1":  "2d4916b9a1292dca8875b1aceaca9beb8de1a5e6"
                                          },
                                          {
                                              "name":  "/com/company/module/SPO3.MGUI.RTEST/4.0.0-SNAPSHOT/SPO3.MGUI.RTEST-bin-4.0.0-SNAPSHOT.zip",
                                              "md5":  "581be6dd9e6615d14db2bb0d05c724e6",
                                              "type":  "application/x-gzip",
                                              "sha1":  "62436ab1aff6cdcdeba59bcac39d6223697398c4"
                                          }
                                      ]
                    }
                ],
    "vcsUrl":  "https://bitbucket-url/project/ec/repo.git"
}

I submit it like this:

Invoke-RestMethod -Uri $url -Method PUT -Body $json -ContentType 'application/json' -Headers $headers
To the URL - https://artifactory-url/artifactory/api/build    

I expect that successful build upload would link my artifact to the build so that I can directly see the artifact from the build info page.

I think my payload information is incorrect but I just can't figure out what I should use.

This is what I see under my artifact build information:

Name:   ivy.xml
Repository Path:    repo-snapshot-local/com/company/module/SPO3.MGUI.RTEST/4.0.0-SNAPSHOT/ivy.xml
Module ID:  com.company.module:SPO3.MGUI.RTEST:4.0.0-SNAPSHOT 

To be specific and if I am correct, this is where I need help (to put correct artifact information to be used for the module id, name, etc:

"modules":  [
                    {
                        "id":  "SPO3.MGUI.RTEST-4.0.0-SNAPSHOT",
                        "artifacts":  [
                                          {
                                              "name":  "/com/company/module/SPO3.MGUI.RTEST/4.0.0-SNAPSHOT/ivy.xml",
                                              "md5":  "a242c427c6c1fdcd33c1c0498fb41324",
                                              "type":  "application/xml",
                                              "sha1":  "2d4916b9a1292dca8875b1aceaca9beb8de1a5e6"
                                          },
                                          {
                                              "name":  "/com/company/module/SPO3.MGUI.RTEST/4.0.0-SNAPSHOT/SPO3.MGUI.RTEST-bin-4.0.0-SNAPSHOT.zip",
                                              "md5":  "581be6dd9e6615d14db2bb0d05c724e6",
                                              "type":  "application/x-gzip",
                                              "sha1":  "62436ab1aff6cdcdeba59bcac39d6223697398c4"
                                          }
                                      ]
                    }
                ]

"repo path" section under the artifactory builds page for my build shows this msg: "No path found (externally resolved or deleted/overwritten)" and this I believe because I am using incorrect payload while submitting the REST call. If I use correct information then this should be populated correctly and I can directly click on it to route to the artifact.

Any help is appreciated here. Thanks

If you have builds in the Build tab but all artifacts have "No path found (externally resolved or deleted/overwritten)" it most probably means that you did not add the needed properties to the uploaded files (build.name, build.number).

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