Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Is there a way to download the artifacts using API?

I can access the artifacts for a build using:

<PlanKey>?buildstate=Successful&max-results=1&expand=results.result.artifacts

 

Result something like:

<artifacts start-index="0" max-result="2" size="2">
 <artifact>
<name>DACPAC</name>
<link href="http://<link>/artifact/shared/DACPAC/" rel="self"/>
<producerJobKey>REG-SQL-JOB1-10</producerJobKey>
<shared>true</shared>
<size>945514</size>
<prettySizeDescription>923 KB</prettySizeDescription>
</artifact>
</artifacts>

...

However, is it possible then to download the artifacts from the artifact link result without resorting to some sort of HTML scraping?

 

2 answers

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?

http://<URL>/rest/api/latest/result/<[projectKey]-[buildKey]>?buildstate=Successful&max-results=1&expand=results.result.artifacts

rsperafico Atlassian Team Mar 18, 2015

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

so what url to use for downloading the artifacts in the loop ?

0 votes
rsperafico Atlassian Team Mar 17, 2015

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:

&lt;artifacts expand="artifacts"&gt;
	&lt;link href="[bamboo-base-url]/rest/api/latest/plan/[projectKey]-[buildKey]/artifact" rel="self"/&gt;
	&lt;artifacts start-index="0" max-result="1" size="1"&gt;
		&lt;artifact&gt;
			&lt;id&gt;1081345&lt;/id&gt;
			&lt;name&gt;Greeting&lt;/name&gt;
			&lt;location/&gt;
			&lt;copyPattern&gt;*.txt&lt;/copyPattern&gt;
			&lt;shared&gt;true&lt;/shared&gt;
		&lt;/artifact&gt;
	&lt;/artifacts&gt;
&lt;/artifacts&gt;

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

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?

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

"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?

@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

Like Kaushik Veluru likes this

Yong, were you able to figure out how to do the iteration or artifact results? 

@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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo 101 Video

G’day Community! As we gear up to introduce Bamboo Data Center to the world, we wanted to make sure that we shared a bit more about Bamboo, the product. Our team has put together an overview video ...

186 views 4 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you