I can access the artifacts for a build using:
<PlanKey>?buildstate=Successful&max-results=1&expand=results.result.artifacts
Result something like:
...
However, is it possible then to download the artifacts from the artifact link result without resorting to some sort of HTML scraping?
OK I can see it will give the artifact but how can i use this to download all the artifacts associated with the plan?
In fact, how is this more useful than the original API url I was using in the question?
Hello Ruban, "-- However, is it possible then to download the artifacts from the artifact link result without resorting to some sort of HTML scraping?" No, as mentioned earlier, it will be required to write a script to loop trough the results and download the artifacts. — Kind regards, Rafael P. Sperafico Atlassian Support
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Ruban,
Thank you for your question.
This is the REST API call associated to Artifacts /plan/{projectKey}-{buildKey}/artifact which will provide you with the following output:
<artifacts expand="artifacts"> <link href="[bamboo-base-url]/rest/api/latest/plan/[projectKey]-[buildKey]/artifact" rel="self"/> <artifacts start-index="0" max-result="1" size="1"> <artifact> <id>1081345</id> <name>Greeting</name> <location/> <copyPattern>*.txt</copyPattern> <shared>true</shared> </artifact> </artifacts> </artifacts>
It will be required to iterate through the result(s) above and use it to build the URL to download the files.
If you find this answer useful, I would kindly ask you to accept it so the same will be visible to others who might be facing the same issue you have inquired.
Thank you for your understanding.
—
Kind regards,
Rafael P. Sperafico
Atlassian Support
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rafael, this doesn't seem to work for me. http://builder:8085/rest/api/latest/plan/UTILS-SVNPERM/artifact?expand=artifacts should return my lone artifact definition but I get <artifacts expand="artifacts"><link href="http://builder:8085/rest/api/latest/plan/UTILS-SVNPERM/artifact"; rel="self"/><artifacts start-index="0" max-result="0" size="0"/></artifacts> Any clue what I'm missing?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, that ONLY works for share artifacts.Verified by looking at source and experimentation. Ok, I must share my artifacts to be able to use this call
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"It will be required to iterate through the result(s) above and use it to build the URL to download the files."
Exactly how to use the results to build the URL? What should go where?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Rafael Please provide more details on how the iteration is done as there is no obvious info on what URL to use for subsequent download requests to get the artifacts, especially for plans that produce multiple artifacts
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yong, were you able to figure out how to do the iteration or artifact results?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Kaushik Veluru Do you know how the URL should be put together to download the artifact? I have no problem getting the information and parsing it. I am just not sure how the URL is formatted
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The REST api ended up not helping me, because most of the interesting artifacts I needed to grab weren't individually named but shared via expressions, e.g. *.deb. As far as I can tell in Feb 2021, the REST API will not detail out individual artifacts that were gathered via an expression, so I had to resort to a small amount of html web scraping.
In Python 3.8, here's my grand html scraping class:
class ParseBambooHTML(HTMLParser):
artifacts_list = list()
def handle_starttag(self, tag, attrs):
if tag == 'a':
for name, value in attrs:
if name == 'href':
self.artifacts_list.append(value)
My entire flow is to use requests to do a GET on the url that you can browse to in a normal browser, e.g.
https://bamboo/artifact/PROJ-ECT/shared/build-latest/example-folder/
(I'm using dummy values there, substitute your bamboo url, project key, and folder, but importantly it has to be a url that shows the files you want to parse/download)
In the example below I'll search for a hypothetical file with 'xxxyyy' in the name, but the version changes each build: (this is massively cut down, but it gives you the gist)
r = session.get(url, timeout=30)
parser = ParseBambooHTML()
parser.feed(r.text)
parser.close()
for line in parser.artifacts_list:
if 'xxxyyy' in line: # '/artifact/PROJ-ECT/shared/build-latest/example-folder/xxxyyy_21.2.17.123.deb'
artifact_uri = line
artifact_filename = artifact_uri.split('/')[-1] # 'xxxyyy_21.2.17.123.deb'
break
With the uri + the file name, you can retrieve the file easily enough now.
Hopefully this added something to the discussion.
-Kelly
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.