problem uploading gradle build scans
Asked by Thomas Einwaller:

we are running gradle tasks with the --scan parameter in our pipelines but most of the time they cannot be views afterwards![Screenshot 2023-04-14 at 16.25.18.png](/t5/image/serverpage/image-id/252039iABB3D337BFDAE559/image-size/large?v=v2&px=999 "Screenshot 2023-04-14 at 16.25.18.png")![Screenshot 2023-04-15 at 22.46.19.png](/t5/image/serverpage/image-id/252040iA9FD679CE30D785E/image-size/large?v=v2&px=999 "Screenshot 2023-04-15 at 22.46.19.png")

what could be the reason?


Answers:
author: Theodora Boudale
body: Hi Thomas,

I do not recognize these screenshots, are these from a third-party application? If so, are you uploading in this application scan results while a Pipelines build is running?

If this is the case, I would suggest adding a flag for verbose output (if available) to the command(s) in your bitbucket-pipelines.yml file that upload these scans. Then, the output of the command(s) may give you an indication of what is going wrong with the upload.

The second screenshot you attached seems to have a link to a 'User Manual', this may have additional info on how to troubleshoot the issue.

Kind regards,  
Theodora

comments: author: Thomas Einwaller
body: the images are from the gradle server where I want to view the results of the build scan

my build step looks something like  

```
- step:
  name: Tests
  size: 2x
  caches:
   - gradlewrapper
   - gradle
  script:
   - ./gradlew test --stacktrace --scan
services:
 - mysql
```

and at the end of the stop the output shows something like

```
Publishing build scan...
https://gradle.com/s/linktoscanresult
```

but when I click I get the errors shown above

The manual behind the links says that I could get more information by looking into

\~/.gradle/build-scan-data/upload-failure.log

is there a way to get that file from my pipeline?


author: Theodora Boudale
body: Hi Thomas,

Just to give you some context, Pipelines builds run in Docker containers. For every step of your build, a Docker container starts (the build container) using the image you have specified in your bitbucket-pipelines.yml file. If you use a service for a step, then a second Docker container will start for the service which will share a network adapter with your build container. The repo is cloned in the build container, and then the commands of the step's script are executed. When the step finishes, these Docker containers get destroyed (so, any files in these containers get destroyed as well).

I can think of a few ways to access the file \~/.gradle/build-scan-data/upload-failure.log:

**1)** Create an after-script for your step:

* <https://support.atlassian.com/bitbucket-cloud/docs/step-options/#After-script>

In the after-script, upload this file to a server of yours or to the **Downloads** page of the repo with the following pipe:

* <https://bitbucket.org/atlassian/bitbucket-upload-file/src/master/>

Please keep in mind that if you upload it to the **Downloads** page of the repo, the file will get replaced the next time a build runs and uploads another file with the same name.

I suggest using an after-script, so that the step won't fail in case the upload of build scans is successful and the file doesn't exist.

**2)** In the after-script of the step, copy this file with a **cp** command to the build directory (exposed in the variable $BITBUCKET_CLONE_DIR) or to a subdirectory of the build directory, and then define this file as an artifact:

* <https://support.atlassian.com/bitbucket-cloud/docs/use-artifacts-in-steps/>

I suggest copying the file because only files in $BITBUCKET_CLONE_DIR and its subdirectories can be defined as artifacts.

Then, while viewing the build log of a specific build on Bitbucket Cloud website, the artifact will be found in the **Artifacts** tab of the build log and can be downloaded from there (it will remain there for 14 days until it expires).

The purpose of artifacts is to make files generated by one step available to subsequent steps, which may not be desirable here. I am just sharing this option as an easy way to get the file from a tab in the build log. You can always disable artifacts download in subsequent steps by adding the following to these steps

```
artifacts:
  download: false
```

* <https://support.atlassian.com/bitbucket-cloud/docs/step-options/#Artifact-downloads>

**3)** You could also use a **cat** command in the after-script to show the contents of this file in the Pipelines build log. This may or may not be convenient, depending on the size of the file and the format of its content.

If you have any questions, please feel free to let me know.

Kind regards,  
Theodora


author: Thomas Einwaller
body: ok, tried those and found that there is no

\~/.gradle/build-scan-data/upload-failure.log

created - which means that the gradle task did not encounter a problem while uploading


author: Theodora Boudale
body: Hi Thomas,

In this case, I would suggest reaching out to the team that provides support for the server you are using, and asking if they can provide you with any additional steps for troubleshooting.

Kind regards,  
Theodora


author: Thomas Einwaller
body: what resolved my problem was to disable background uploading as explained here <https://docs.gradle.com/enterprise/gradle-plugin/#configuring_background_uploading>


author: Theodora Boudale
body: That's good to hear Thomas, thank you for sharing the solution here!


Tags: bitbucket-cloud

cloud