Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. ./.travis/setup_ramdisk.sh
  4. #
  5. # Configure Maven settings and install some script utilities
  6. #
  7. configureTravis() {
  8. mkdir -p ~/.local
  9. curl -sSL https://github.com/SonarSource/travis-utils/tarball/v61 | tar zx --strip-components 1 -C ~/.local
  10. # shellcheck disable=SC1090
  11. source ~/.local/bin/install
  12. }
  13. configureTravis
  14. #
  15. # Travis fails on timeout when build does not print logs
  16. # during 10 minutes. This aims to bypass this
  17. # behavior when building the slow sonar-server sub-project.
  18. #
  19. keep_alive() {
  20. while true; do
  21. echo -en "\a"
  22. sleep 60
  23. done
  24. }
  25. keep_alive &
  26. # When a pull request is open on the branch, then the job related
  27. # to the branch does not need to be executed and should be canceled.
  28. # It does not book slaves for nothing.
  29. # @TravisCI please provide the feature natively, like at AppVeyor or CircleCI ;-)
  30. cancel_branch_build_with_pr || if [[ $? -eq 1 ]]; then exit 0; fi
  31. # Used by Next
  32. INITIAL_VERSION=$(grep version gradle.properties | awk -F= '{print $2}')
  33. export INITIAL_VERSION
  34. # use generic environments to remove coupling with Travis ; see setup_promote_environment
  35. export GITHUB_REPO=${TRAVIS_REPO_SLUG}
  36. export BUILD_NUMBER=$TRAVIS_BUILD_NUMBER
  37. export PIPELINE_ID=${BUILD_NUMBER}
  38. if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  39. export GIT_SHA1=${TRAVIS_COMMIT} # $CIRRUS_CHANGE_IN_REPO
  40. export GIT_BRANCH=$TRAVIS_BRANCH
  41. export STAGE_TYPE="branch"
  42. export STAGE_ID=${GIT_BRANCH}
  43. else
  44. export GIT_SHA1=${TRAVIS_PULL_REQUEST_SHA}
  45. export GIT_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH
  46. export PULL_REQUEST_BASE_BRANCH=$TRAVIS_BRANCH
  47. export PULL_REQUEST_NUMBER=$TRAVIS_PULL_REQUEST
  48. export STAGE_TYPE="pr_number"
  49. export STAGE_ID=${PULL_REQUEST_NUMBER}
  50. fi
  51. echo "======= SHA1 is ${GIT_SHA1} on branch '${GIT_BRANCH}'. Burgr stage '${STAGE_TYPE} with stage ID '${STAGE_ID} ======="
  52. # Analyse SonarQube on NEXT
  53. export SONAR_HOST_URL=https://next.sonarqube.com/sonarqube
  54. # Fetch all commit history so that SonarQube has exact blame information
  55. # for issue auto-assignment
  56. # This command can fail with "fatal: --unshallow on a complete repository does not make sense"
  57. # if there are not enough commits in the Git repository (even if Travis executed git clone --depth 50).
  58. # For this reason errors are ignored with "|| true"
  59. git fetch --unshallow || true
  60. BUILD_START_DATETIME=$(date --utc +%FT%TZ)
  61. ./gradlew build --no-daemon --console plain
  62. BUILD_END_DATETIME=$(date --utc +%FT%TZ)
  63. # exclude external pull requests
  64. if [[ -n "${NEXT_TOKEN-}" ]]; then
  65. notify_burgr "build" "build" "$TRAVIS_JOB_WEB_URL" "$BUILD_START_DATETIME" "$BUILD_END_DATETIME"
  66. sonar_params=(-Dsonar.projectKey=sonarqube
  67. -Dsonar.host.url="$SONAR_HOST_URL"
  68. -Dsonar.login="$NEXT_TOKEN"
  69. -Dsonar.analysis.buildNumber="$BUILD_NUMBER"
  70. -Dsonar.analysis.pipeline="$BUILD_NUMBER"
  71. -Dsonar.analysis.sha1="$GIT_SHA1"
  72. -Dsonar.analysis.repository="$TRAVIS_REPO_SLUG")
  73. if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
  74. echo '======= Analyze pull request'
  75. ./gradlew jacocoTestReport :server:sonar-web:yarn_validate-ci sonarqube --info --no-daemon --console plain \
  76. "${sonar_params[@]}" \
  77. -Dsonar.analysis.prNumber="$PULL_REQUEST_NUMBER" \
  78. -Dsonar.pullrequest.branch="$GIT_BRANCH" \
  79. -Dsonar.pullrequest.base="$PULL_REQUEST_BASE_BRANCH" \
  80. -Dsonar.pullrequest.key="$PULL_REQUEST_NUMBER" \
  81. -Dsonar.pullrequest.provider=github \
  82. -Dsonar.pullrequest.github.repository="$TRAVIS_REPO_SLUG"
  83. elif [ "${TRAVIS_BRANCH}" == "master" ]; then
  84. echo '======= Analyze master'
  85. ./gradlew jacocoTestReport :server:sonar-web:yarn_validate-ci sonarqube --info --no-daemon --console plain \
  86. "${sonar_params[@]}" \
  87. -Dsonar.projectVersion="$INITIAL_VERSION"
  88. else
  89. echo '======= Analyze branch'
  90. ./gradlew jacocoTestReport :server:sonar-web:yarn_validate-ci sonarqube --info --no-daemon --console plain \
  91. "${sonar_params[@]}" \
  92. -Dsonar.branch.name="$GIT_BRANCH" \
  93. -Dsonar.projectVersion="$INITIAL_VERSION"
  94. fi
  95. # Wait for 5mins, hopefully the report will be processed.
  96. sleep 5m
  97. ./.travis/run_iris.sh
  98. fi