Access shared artifact from a script

I need to download artifacts from other plans to my build plan. However, I need it to be more flexible than I can make it with the artifact download task. More specifically I need:

  1. Possible to get artifact from a specific branch, not necessary with the same name as the branch of the current plan.
  2. Possible to get artifact from a specific build, not only the latest successful build.

Can I do this from a script? The agent runs on Windows.

1 answer

1 accepted

0 votes
Accepted answer

I'd use the web side of things /browse/PLAN-KEY-38/artifact/shared/


/artifact/PLAN-KEY/shared/build-38/ is working better for me.

Adding example powershell script:

function DownloadFolderContents($url, $baseFolder = "./")
    if (!(Test-Path $baseFolder))
        New-Item $baseFolder -ItemType Directory > $null
    $basePath = Resolve-Path $baseFolder
    $html = (new-object System.Net.WebClient).DownloadString($url) -split "\n"
    $html |% `
        if ($_ -notmatch "<td><img .* alt=`"\((dir|file)\)`".*<a href=`"((?!`").*)`">(.*)</a>")
        { return }
        $type = $Matches[1]
        $path = $Matches[2]
        $name = $Matches[3]
        if ($type -eq "file")
        { (new-object System.Net.WebClient).DownloadFile("$bambooHost$path", $(Join-Path $basePath $name)) }
        { DownloadFolderContents -url "$bambooHost$path" -baseFolder $(Join-Path $baseFolder $name)}

$bambooHost = "http://YourOwnBambooHost"
$targetPlanKey = "PLAN-KEY"
$targetBuildNumber = "38"
$artifactName = "ArtifactName"

$url = "$bambooHost/artifact/$targetPlanKey/shared/build-$targetBuildNumber/$artifactName"


Suggest an answer

Log in or Sign up to answer
Community showcase
Asked Dec 06, 2018 in Jira Ops

I'm John Allspaw, Ask Me Anything about incident analysis and postmortems

I'm John Allspaw, co-founder of   Adaptive Capacity Labs, where we help teams use their incidents to learn and improve. We bring research-driven methods and approaches to drive effective inciden...

5,517 views 21 17
View question

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you