]> source.dussan.org Git - sonarqube.git/commitdiff
BUILD-1457 report failure to Burgr
authorJulien Carsique <julien.carsique@sonarsource.com>
Tue, 29 Mar 2022 10:38:48 +0000 (12:38 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 30 Mar 2022 13:38:05 +0000 (13:38 +0000)
Move passed build notification to Burgr at the end (after build, analysis and iris)
Report build failure to Burgr

.travis.yml
.travis/setup_environment.sh [new file with mode: 0755]
travis.sh

index 25f436a3fffb0bd7d44fb0ab94ad2fb0e39758f1..7e84081f81a3d2bc8d1f138e5fc0fd02b61b7c6d 100644 (file)
@@ -49,3 +49,7 @@ notifications:
   slack:
     secure: PCekbN71ZmuOt82JUFmlhzxlx3wrXucSIpvxxWdZn9lfsPYQAtXCoOESaHjIVIpggsC5HSAic3HiedsWbuDk/XojmPrDCrfjgYG2wiuSuQlAa60WvzTPqXdRmUXyMQgItaAQbRfZP7kN9No/v8TZDfg5kT3i9ewy0bsfExpjAuo=
   on_start: always
+
+after_failure:
+  - source ./.travis/setup_environment.sh
+  - notify_burgr "build" "build" "$TRAVIS_JOB_WEB_URL" "$(cat /tmp/build_start_time)" "$(date --utc +%FT%TZ)" "failed" || true
diff --git a/.travis/setup_environment.sh b/.travis/setup_environment.sh
new file mode 100755 (executable)
index 0000000..2f11f41
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+# Sets up the environment to be able to send notifications to burgr
+# use generic environments to remove coupling with Travis ; see setup_promote_environment
+
+export GITHUB_REPO=${TRAVIS_REPO_SLUG}
+export BUILD_NUMBER=$TRAVIS_BUILD_NUMBER
+export PIPELINE_ID=${BUILD_NUMBER}
+if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
+  export GIT_SHA1=${TRAVIS_COMMIT} # $CIRRUS_CHANGE_IN_REPO
+  export GIT_BRANCH=$TRAVIS_BRANCH
+  export STAGE_TYPE="branch"
+  export STAGE_ID=${GIT_BRANCH}
+else
+  export GIT_SHA1=${TRAVIS_PULL_REQUEST_SHA}
+  export GIT_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH
+  export PULL_REQUEST_BASE_BRANCH=$TRAVIS_BRANCH
+  export PULL_REQUEST_NUMBER=$TRAVIS_PULL_REQUEST
+  export STAGE_TYPE="pr_number"
+  export STAGE_ID=${PULL_REQUEST_NUMBER}
+fi
+echo "======= SHA1 is ${GIT_SHA1} on branch '${GIT_BRANCH}'. Burgr stage '${STAGE_TYPE} with stage ID '${STAGE_ID} ======="
index 79844a87ed30f31d13654a21d9002e37498ad3f6..c592ad3cea76410898e904ac28dab2b6c9fba40d 100755 (executable)
--- a/travis.sh
+++ b/travis.sh
@@ -8,7 +8,7 @@ set -euo pipefail
 #
 configureTravis() {
   mkdir -p ~/.local
-  curl -sSL https://github.com/SonarSource/travis-utils/tarball/v61 | tar zx --strip-components 1 -C ~/.local
+  curl -sSL https://github.com/SonarSource/travis-utils/tarball/v62 | tar zx --strip-components 1 -C ~/.local
   # shellcheck disable=SC1090
   source ~/.local/bin/install
 }
@@ -37,24 +37,7 @@ cancel_branch_build_with_pr || if [[ $? -eq 1 ]]; then exit 0; fi
 INITIAL_VERSION=$(grep version gradle.properties | awk -F= '{print $2}')
 export INITIAL_VERSION
 
-# use generic environments to remove coupling with Travis ; see setup_promote_environment
-export GITHUB_REPO=${TRAVIS_REPO_SLUG}
-export BUILD_NUMBER=$TRAVIS_BUILD_NUMBER
-export PIPELINE_ID=${BUILD_NUMBER}
-if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
-  export GIT_SHA1=${TRAVIS_COMMIT} # $CIRRUS_CHANGE_IN_REPO
-  export GIT_BRANCH=$TRAVIS_BRANCH
-  export STAGE_TYPE="branch"
-  export STAGE_ID=${GIT_BRANCH}
-else
-  export GIT_SHA1=${TRAVIS_PULL_REQUEST_SHA}
-  export GIT_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH
-  export PULL_REQUEST_BASE_BRANCH=$TRAVIS_BRANCH
-  export PULL_REQUEST_NUMBER=$TRAVIS_PULL_REQUEST
-  export STAGE_TYPE="pr_number"
-  export STAGE_ID=${PULL_REQUEST_NUMBER}
-fi
-echo "======= SHA1 is ${GIT_SHA1} on branch '${GIT_BRANCH}'. Burgr stage '${STAGE_TYPE} with stage ID '${STAGE_ID} ======="
+source ./.travis/setup_environment.sh
 
 # Analyse SonarQube on NEXT
 export SONAR_HOST_URL=https://next.sonarqube.com/sonarqube
@@ -67,13 +50,11 @@ export SONAR_HOST_URL=https://next.sonarqube.com/sonarqube
 git fetch --unshallow || true
 
 BUILD_START_DATETIME=$(date --utc +%FT%TZ)
+echo "$BUILD_START_DATETIME" > /tmp/build_start_time
 ./gradlew build --no-daemon --console plain
-BUILD_END_DATETIME=$(date --utc +%FT%TZ)
 
 # exclude external pull requests
 if [[ -n "${NEXT_TOKEN-}" ]]; then
-  notify_burgr "build" "build" "$TRAVIS_JOB_WEB_URL" "$BUILD_START_DATETIME" "$BUILD_END_DATETIME"
-
   sonar_params=(-Dsonar.projectKey=sonarqube
     -Dsonar.host.url="$SONAR_HOST_URL"
     -Dsonar.login="$NEXT_TOKEN"
@@ -108,4 +89,7 @@ if [[ -n "${NEXT_TOKEN-}" ]]; then
   # Wait for 5mins, hopefully the report will be processed.
   sleep 5m
   ./.travis/run_iris.sh
+
+  BUILD_END_DATETIME=$(date --utc +%FT%TZ)
+  notify_burgr "build" "build" "$TRAVIS_JOB_WEB_URL" "$BUILD_START_DATETIME" "$BUILD_END_DATETIME" || true
 fi