You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

travis.sh 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash -v
  2. set -euo pipefail
  3. function configureTravis {
  4. mkdir -p ~/.local
  5. curl -sSL https://github.com/SonarSource/travis-utils/tarball/v23 | tar zx --strip-components 1 -C ~/.local
  6. source ~/.local/bin/install
  7. }
  8. configureTravis
  9. function strongEcho {
  10. echo ""
  11. echo "================ $1 ================="
  12. }
  13. case "$TARGET" in
  14. CI)
  15. if [ "${TRAVIS_BRANCH}" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  16. strongEcho 'Build, deploy and analyze master'
  17. SONAR_PROJECT_VERSION=`maven_expression "project.version"`
  18. # Do not deploy a SNAPSHOT version but the release version related to this build
  19. set_maven_build_version $TRAVIS_BUILD_NUMBER
  20. export MAVEN_OPTS="-Xmx1G -Xms128m"
  21. mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy sonar:sonar \
  22. -Pcoverage-per-test,deploy-sonarsource \
  23. -Dmaven.test.redirectTestOutputToFile=false \
  24. -Dsonar.host.url=$SONAR_HOST_URL \
  25. -Dsonar.login=$SONAR_TOKEN \
  26. -Dsonar.projectVersion=$SONAR_PROJECT_VERSION \
  27. -B -e -V
  28. elif [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ -n "${GITHUB_TOKEN-}" ]; then
  29. strongEcho 'Build and analyze pull request, no deploy'
  30. # No need for Maven phase "install" as the generated JAR file does not need to be installed
  31. # in Maven local repository. Phase "verify" is enough.
  32. mvn org.jacoco:jacoco-maven-plugin:prepare-agent verify sonar:sonar \
  33. -Dmaven.test.redirectTestOutputToFile=false \
  34. -Dsonar.analysis.mode=issues \
  35. -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST \
  36. -Dsonar.github.repository=$TRAVIS_REPO_SLUG \
  37. -Dsonar.github.oauth=$GITHUB_TOKEN \
  38. -Dsonar.host.url=$SONAR_HOST_URL \
  39. -Dsonar.login=$SONAR_TOKEN \
  40. -B -e -V
  41. else
  42. strongEcho 'Build, no analysis, no deploy'
  43. # No need for Maven phase "install" as the generated JAR file does not need to be installed
  44. # in Maven local repository. Phase "verify" is enough.
  45. mvn verify \
  46. -Dmaven.test.redirectTestOutputToFile=false \
  47. -B -e -V
  48. fi
  49. ;;
  50. IT)
  51. if [ "${SQ_VERSION}" = "DEV" ]
  52. then
  53. build_snapshot "SonarSource/sonarqube"
  54. fi
  55. # Need install because ITs will take artifact from local repo
  56. mvn install -B -e -V -Dsource.skip=true -Denforcer.skip=true -Danimal.sniffer.skip=true -Dmaven.test.skip=true
  57. cd it
  58. mvn -Dsonar.runtimeVersion="$SQ_VERSION" -Dmaven.test.redirectTestOutputToFile=false verify -e -B -V
  59. ;;
  60. *)
  61. echo "Unexpected TARGET value: $TARGET"
  62. exit 1
  63. ;;
  64. esac