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 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #!/bin/bash
  2. set -euo pipefail
  3. ./.travis/setup_ramdisk.sh
  4. #
  5. # A (too) old version of JDK8 is installed by default on Travis.
  6. # This method is preferred over Travis apt oracle-java8-installer because
  7. # JDK is kept in cache. It does not need to be downloaded from Oracle
  8. # at each build.
  9. #
  10. function installJdk8 {
  11. echo "Setup JDK 1.8u161"
  12. mkdir -p ~/jvm
  13. pushd ~/jvm > /dev/null
  14. if [ ! -d "jdk1.8.0_161" ]; then
  15. wget --quiet --continue --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz
  16. tar xzf jdk-8u161-linux-x64.tar.gz
  17. rm jdk-8u161-linux-x64.tar.gz
  18. fi
  19. popd > /dev/null
  20. export JAVA_HOME=~/jvm/jdk1.8.0_161
  21. export PATH=$JAVA_HOME/bin:$PATH
  22. }
  23. #
  24. # Maven 3.2.5 is installed by default on Travis. Maven 3.5 is preferred.
  25. #
  26. function installMaven {
  27. echo "Setup Maven"
  28. mkdir -p ~/maven
  29. pushd ~/maven > /dev/null
  30. if [ ! -d "apache-maven-3.5" ]; then
  31. echo "Download Maven 3.5"
  32. curl -sSL https://archive.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz | tar zx -C ~/maven
  33. fi
  34. popd > /dev/null
  35. export M2_HOME=~/maven/apache-maven-3.5.0
  36. export PATH=$M2_HOME/bin:$PATH
  37. }
  38. function installNode {
  39. set +u
  40. source ~/.nvm/nvm.sh && nvm install 8
  41. set -u
  42. }
  43. #
  44. # Replaces the version defined in sources, usually x.y-SNAPSHOT,
  45. # by a version identifying the build.
  46. # The build version is composed of 4 fields, including the semantic version and
  47. # the build number provided by Travis.
  48. #
  49. # Exported variables:
  50. # - INITIAL_VERSION: version as defined in pom.xml
  51. # - BUILD_VERSION: version including the build number
  52. # - PROJECT_VERSION: target Maven version. The name of this variable is important because
  53. # it's used by QA when extracting version from Artifactory build info.
  54. #
  55. # Example of SNAPSHOT
  56. # INITIAL_VERSION=6.3-SNAPSHOT
  57. # BUILD_VERSION=6.3.0.12345
  58. # PROJECT_VERSION=6.3.0.12345
  59. #
  60. # Example of RC
  61. # INITIAL_VERSION=6.3-RC1
  62. # BUILD_VERSION=6.3.0.12345
  63. # PROJECT_VERSION=6.3-RC1
  64. #
  65. # Example of GA
  66. # INITIAL_VERSION=6.3
  67. # BUILD_VERSION=6.3.0.12345
  68. # PROJECT_VERSION=6.3
  69. #
  70. function fixBuildVersion {
  71. export INITIAL_VERSION=`maven_expression "project.version"`
  72. # remove suffix -SNAPSHOT or -RC
  73. without_suffix=`echo $INITIAL_VERSION | sed "s/-.*//g"`
  74. IFS=$'.'
  75. fields_count=`echo $without_suffix | wc -w`
  76. unset IFS
  77. if [ $fields_count -lt 3 ]; then
  78. export BUILD_VERSION="$without_suffix.0.$TRAVIS_BUILD_NUMBER"
  79. else
  80. export BUILD_VERSION="$without_suffix.$TRAVIS_BUILD_NUMBER"
  81. fi
  82. if [[ "${INITIAL_VERSION}" == *"-SNAPSHOT" ]]; then
  83. # SNAPSHOT
  84. export PROJECT_VERSION=$BUILD_VERSION
  85. mvn org.codehaus.mojo:versions-maven-plugin:2.2:set -DnewVersion=$PROJECT_VERSION -DgenerateBackupPoms=false -B -e
  86. else
  87. # not a SNAPSHOT: milestone, RC or GA
  88. export PROJECT_VERSION=$INITIAL_VERSION
  89. fi
  90. echo "Build Version : $BUILD_VERSION"
  91. echo "Project Version: $PROJECT_VERSION"
  92. }
  93. #
  94. # Configure Maven settings and install some script utilities
  95. #
  96. function configureTravis {
  97. mkdir -p ~/.local
  98. curl -sSL https://github.com/SonarSource/travis-utils/tarball/v41 | tar zx --strip-components 1 -C ~/.local
  99. source ~/.local/bin/install
  100. }
  101. configureTravis
  102. # When a pull request is open on the branch, then the job related
  103. # to the branch does not need to be executed and should be canceled.
  104. # It does not book slaves for nothing.
  105. # @TravisCI please provide the feature natively, like at AppVeyor or CircleCI ;-)
  106. cancel_branch_build_with_pr || if [[ $? -eq 1 ]]; then exit 0; fi
  107. # configure environment variables for Artifactory
  108. export GIT_COMMIT=$TRAVIS_COMMIT
  109. export BUILD_NUMBER=$TRAVIS_BUILD_NUMBER
  110. if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  111. export GIT_BRANCH=$TRAVIS_BRANCH
  112. unset PULL_REQUEST_BRANCH_TARGET
  113. unset PULL_REQUEST_NUMBER
  114. else
  115. export GIT_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH
  116. export PULL_REQUEST_BRANCH_TARGET=$TRAVIS_BRANCH
  117. export PULL_REQUEST_NUMBER=$TRAVIS_PULL_REQUEST
  118. fi
  119. case "$TARGET" in
  120. BUILD)
  121. installJdk8
  122. installMaven
  123. installNode
  124. fixBuildVersion
  125. # Minimal Maven settings
  126. export MAVEN_OPTS="-Xmx1G -Xms128m"
  127. MAVEN_ARGS="-T 1C -Dmaven.test.redirectTestOutputToFile=false -Dsurefire.useFile=false -B -e -V -DbuildVersion=$BUILD_VERSION -Dtests.es.logger.level=WARN -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn"
  128. # Fetch all commit history so that SonarQube has exact blame information
  129. # for issue auto-assignment
  130. # This command can fail with "fatal: --unshallow on a complete repository does not make sense"
  131. # if there are not enough commits in the Git repository (even if Travis executed git clone --depth 50).
  132. # For this reason errors are ignored with "|| true"
  133. git fetch --unshallow || true
  134. if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  135. echo 'Build and analyze master'
  136. mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy \
  137. $MAVEN_ARGS \
  138. -Pdeploy-sonarsource,release
  139. mvn sonar:sonar \
  140. -Dsonar.host.url=$SONAR_HOST_URL \
  141. -Dsonar.login=$SONAR_TOKEN \
  142. -Dsonar.projectVersion=$INITIAL_VERSION \
  143. -Dsonar.analysis.buildNumber=$BUILD_NUMBER \
  144. -Dsonar.analysis.pipeline=$BUILD_NUMBER \
  145. -Dsonar.analysis.sha1=$GIT_COMMIT \
  146. -Dsonar.analysis.repository=$TRAVIS_REPO_SLUG
  147. elif [[ "$TRAVIS_BRANCH" == "branch-"* ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  148. echo 'Build release branch'
  149. mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy \
  150. $MAVEN_ARGS \
  151. -Pdeploy-sonarsource,release
  152. mvn sonar:sonar \
  153. -Dsonar.host.url=$SONAR_HOST_URL \
  154. -Dsonar.login=$SONAR_TOKEN \
  155. -Dsonar.branch.name=$TRAVIS_BRANCH \
  156. -Dsonar.projectVersion=$INITIAL_VERSION \
  157. -Dsonar.analysis.buildNumber=$BUILD_NUMBER \
  158. -Dsonar.analysis.pipeline=$BUILD_NUMBER \
  159. -Dsonar.analysis.sha1=$GIT_COMMIT \
  160. -Dsonar.analysis.repository=$TRAVIS_REPO_SLUG
  161. elif [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ -n "${GITHUB_TOKEN:-}" ]; then
  162. echo 'Build and analyze internal pull request'
  163. mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy \
  164. $MAVEN_ARGS \
  165. -Dsource.skip=true \
  166. -Pdeploy-sonarsource
  167. # TODO remove the sonar.pullrequest.github.* settings after sonar-core-plugins 7.1.0.330 is deployed on Next
  168. mvn sonar:sonar \
  169. -Dsonar.host.url=$SONAR_HOST_URL \
  170. -Dsonar.login=$SONAR_TOKEN \
  171. -Dsonar.branch.name=$TRAVIS_PULL_REQUEST_BRANCH \
  172. -Dsonar.branch.target=$TRAVIS_BRANCH \
  173. -Dsonar.analysis.buildNumber=$BUILD_NUMBER \
  174. -Dsonar.analysis.pipeline=$BUILD_NUMBER \
  175. -Dsonar.analysis.sha1=$TRAVIS_PULL_REQUEST_SHA \
  176. -Dsonar.analysis.prNumber=$TRAVIS_PULL_REQUEST \
  177. -Dsonar.analysis.repository=$TRAVIS_REPO_SLUG \
  178. -Dsonar.pullrequest.id=$TRAVIS_PULL_REQUEST \
  179. -Dsonar.pullrequest.github.id=$TRAVIS_PULL_REQUEST \
  180. -Dsonar.pullrequest.github.repository=$TRAVIS_REPO_SLUG
  181. else
  182. echo 'Build feature branch or external pull request'
  183. mvn deploy $MAVEN_ARGS -Pdeploy-sonarsource,release
  184. fi
  185. ./run-integration-tests.sh "Lite" ""
  186. ;;
  187. WEB_TESTS)
  188. installNode
  189. curl -o- -L https://yarnpkg.com/install.sh | bash
  190. export PATH=$HOME/.yarn/bin:$PATH
  191. cd server/sonar-web && yarn && yarn validate
  192. ;;
  193. *)
  194. echo "Unexpected TARGET value: $TARGET"
  195. exit 1
  196. ;;
  197. esac