Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Access shared artifact from a script

Kristian Svensson January 21, 2014

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
Answer accepted
Jason Monsorno
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2014

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

EDIT:

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

Jason Monsorno
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2014

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)) }
        else
        { 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"

DownloadFolderContents($url)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events