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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Reporting sonarcube analysis even if the build fails

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.

1 answer

1 accepted

0 votes
Answer accepted
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Apr 20, 2022

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events