Is there a way to report code analysis on sonarcube dashbaord even if the build fails? Is there a way to write a script in yml file to do the above? Please let me know.
Hey @Sandeep_Dash ,
My suggestion would for you to make use of the after-script functionality of Bitbucket Pipelines. With after-script you can define one or commands to be executed as soon as your step is completed, regardless if the step failed or succeed.
Please find below an example of using after-script keyword :
pipelines:
default:
- step:
name: Build and test
script:
- npm install
- npm test
after-script:
- echo "This is my first after script command"
- echo "This is my first after script command"
- ./my_script.sh #invoking a script
In the example above, the 3 commands of after-script section will be executed both if the prior npm commands fail or succeed. For more details about the after-script syntax you can refer to this documentation.
If you want the after-script to only be executed in one of these scenarios (only when step succeed or only when the step failed) you can make use of the environment variable BITBUCKET_EXIT_CODE - values can be 0 (success) or 1 (failed) - and create an if statement in your YML, like below :
after-script:
- if [ "$BITBUCKET_EXIT_CODE" != 1 ]; then exit 0 ; fi - echo "This command will only be executed if the step failed"
You can also make use of pipes in the after-script section. Sonar has developed some pipes that can be used in Bitbucket pipelines which might be useful for your use-case :
Hope that helps to address your questions. Do let us know in case you have any doubt.
Thank you, @Sandeep_Dash .
Kind regards,
Patrik S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.