Unable to download build artifact via web request
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
When using wget to download a build artifact via a web request with HTTP Basic Authentication and Anonymous access disabled in Bamboo, an error occurs and the downloaded file is corrupted. However, when manually entering the username and password in the Web interface, the artifact is downloaded correctly.
Environment
- Any Bamboo version
- wget
Diagnosis
While fetching a build artifact from Bamboo via a web request using wget:
$ wget --user user --password <PASSWORD> -N <bamboo-artifact-url>
The following error is present in the atlassian-bamboo.log
file:
2023-03-07 17:16:06,658 ERROR [http-nio-8085-exec-1] [AbstractDownloadStrategy] Access denied for downloads URL /<bamboo-artifact-url>
The location of the atlassian-bamboo.log
file can be viewed in Bamboo's System information under the Bamboo paths section
[root@xxx:~]# wget -N <bamboo-artifact-url>
{-}{{-}}<date-time>{{-}}{-} <bamboo-artifact-url>
Resolving <bamboo-url> (bamboo-url)... <bamboo-ip>
Connecting to <bamboo-url> (<bamboo-url>)|<bamboo-ip>|:443... connected.
HTTP request sent, awaiting response... 302
Location: <bamboo-artifact-url> [following]
{-}{{-}}<date-time>{{-}}{-} <bamboo-artifact-url>
Reusing existing connection to <bamboo-url>:443.
HTTP request sent, awaiting response... 200
Length: unspecified [text/html]
Saving to: '<artifact-name>'
Cause
This happens because Bamboo does not send HTTP request authentication challenges back to the client when an Artifact URL is requested.
Solution
Option 1: Use the --auth-no-challenge
argument with wget. Since wget 1.10.2, Basic HTTP authentication is only sent when the target HTTP server responds with an authentication challenge. By using the '--auth-no-challenge' parameter, wget will send Basic HTTP authentication information (plaintext username and password) for all requests.
$ wget --auth-no-challenge --http-user <user> --http-password <password> <bamboo-artifact-url>
Option 2: Use curl and follow redirects. curl sends Basic HTTP authentication challenges to all requests by default when a username is provided. Make sure to follow redirects by setting the --location
or -L
arguments:
$ curl --location --user <user>:<password> <bamboo-artifact-url> -o artifact.txt