11#! /usr/bin/env bash
22
33MAIN_DEV_BRANCH=" develop"
4+
45BRANCH_SONAR_PROPERTY=" sonar.branch.name"
56BRANCH_SONAR_TARGET_PROPERTY=" sonar.branch.target"
67
7- function add_sonar_property {
8+ PR_SONAR_BRANCH_PROPERTY=" sonar.pullrequest.branch"
9+ PR_KEY_PROPERTY=" sonar.pullrequest.key"
10+ PR_SONAR_BASE_PROPERTY=" sonar.pullrequest.base"
11+ PR_SONAR_TOKEN_PROPERTY=" sonar.pullrequest.github.token.secured"
812
13+ # Add property to file
14+ function add_sonar_property {
915 echo " $1 =$2 " >> sonar-project.properties
1016}
1117
18+
1219if [ " $TRAVIS_PULL_REQUEST " == " false" ]; then
1320 BRANCH=$TRAVIS_BRANCH ;
1421 PR_BRANCH=" "
2027
2128fi
2229
23- add_sonar_property " sonar.pullrequest.github.token.secured" " ${GITHUB_TRAVISCI_TOKEN} "
2430
25- # We are updating sonar_properties only when is not a develop
26- # if its a pull request we will create a separate
31+ # Are we running on develop branch ?
32+ echo " Check if we running from develop or on branch "
2733if [ " ${TRAVIS_REPO_SLUG} " = " ${UTPLSQL_REPO} " ] && [[ ! " ${BRANCH} " =~ ^(release/v[0-9]+\. [0-9]+\. [0-9]+.* | " ${MAIN_DEV_BRANCH} " )$ ]]; then
28- echo " Updating sonar properties to include branch name"
29-
30- add_sonar_property " ${BRANCH_SONAR_PROPERTY} " " ${BRANCH} "
3134
32- if [ ! -z " $PR_BRANCH " ]; then
33- echo " Updating sonar properties to include pr target branch name"
34- add_sonar_property " ${BRANCH_SONAR_TARGET_PROPERTY} " " ${PR_BRANCH} "
35- else
35+ if [ " $TRAVIS_PULL_REQUEST " == " false" ]; then
36+ echo " Updating sonar properties to include branch name"
37+ add_sonar_property " ${BRANCH_SONAR_PROPERTY} " " ${BRANCH} "
3638 add_sonar_property " ${BRANCH_SONAR_TARGET_PROPERTY} " " ${MAIN_DEV_BRANCH} "
37- fi
38-
39+ else
40+ echo " Updating sonar properties to include pull request name"
41+ add_sonar_property " ${PR_SONAR_TOKEN_PROPERTY} " " ${GITHUB_TRAVISCI_TOKEN} "
42+ add_sonar_property " ${PR_SONAR_BRANCH_PROPERTY} " " ${BRANCH} "
43+ add_sonar_property " ${PR_KEY_PROPERTY} " " ${PR} "
44+ add_sonar_property " ${PR_SONAR_BASE_PROPERTY} " " ${PR_BRANCH} "
45+ fi
3946else
4047 echo " No need to update sonar we building on release or develop"
4148fi
4249
50+ # debug
51+ cat sonar-project.properties
52+
4353# Execute Sonar scanner
44- sonar-scanner
54+ # sonar-scanner
0 commit comments