Caching for Sonar-scanner in Bitbucket Pipelines does not work

Following the example for Bitbucket Pipelines integration with Sonar Scanner on a NodeJS project, the instructed cache usage does not work. This has the effect of making scan times a LOT longer, on NodeJS projects.

This can even be seen in the sample repo pipeline
https://bitbucket.org/sonarsource/sample-nodejs-project/addon/pipelines/home#!/results/120

I can only assume that this is because it runs in pipes, whereas (for example) the Maven example runs in the same pipeline / step as the command which calls it, so the cache is available.

I’m not sure how / if Bitbucket Pipelines allow access to the output files from a Pipe

Edit:
The only documentation I can find related to sharing files from a pipe is here:
https://confluence.atlassian.com/bitbucket/how-to-write-a-pipe-for-bitbucket-pipelines-966051288.html#HowtowriteapipeforBitbucketPipelines-Advancedtipsandsecrets

It says you need to adjust permissions, which looking at the source for the scanner, I don’t think it does

2 Likes

Can you please clarify where this is “instructed”?


In any case, if I understand correctly, your question concerns snippets like this:

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        caches:
          - sonar
        script:
          - pipe: sonarsource/sonarcloud-scan:1.0.1

Contrary to the comment, the defined sonar cache will not be used by the pipe, and it will download artifacts from SonarCloud on every run.

I’m not sure how we can improve this at our side. I initiatiated a discussion with Bitbucket:

If you meant something else, please let us know!

1 Like

This is indeed what I was getting at, thanks Janos.

I’ve subscribed to your question on the Atlassian Community page, hopefully it will get replies.

1 Like

Only when using ~/.sonar/cache sonar will error on every build with the cached directory.

err.txt (9.4 KB)
bitbucket-pipelines.yml.txt (812 Bytes)

I know that you are waiting on Atlassian to add support for this feature on their end, but I would also just like to voice my company’s interest in some sort of caching for the BitBucket pipe, or really anyway to speed up analysis time. If anyone has any tips, please lmk!

I cant get the cache to work and saw this issue. ANy updates on this issue on how to get cache to work ? Without caching, our build times have significantly increased