X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=blobdiff_plain;f=shell%2Frtd-trigger-build.sh;h=673d0f9af13c4bb9867d873584aeec837b2a1937;hb=7265d1f18e9895a1d86449c3ee9fa57edd023df9;hp=6df9d0501f7b43da2a99ce396010021283ed64e5;hpb=1c6c45e731e8941f3ff7894641ca7aee77a80426;p=releng%2Fglobal-jjb.git diff --git a/shell/rtd-trigger-build.sh b/shell/rtd-trigger-build.sh index 6df9d050..673d0f9a 100644 --- a/shell/rtd-trigger-build.sh +++ b/shell/rtd-trigger-build.sh @@ -8,12 +8,32 @@ # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html ############################################################################## +# Call cURL to trigger a build in RTD via the Generic API +# +# Paramters: +# RTD_BUILD_URL: The unique build URL for the project. +# Check Admin > Integrations > Generic API incoming webhook. +# +# RTD_TOKEN: The unique token for the project Generic webhook. +# Check Admin > Integrations > Generic API incoming webhook. + echo "---> rtd-trigger-build.sh" -if [ "$GERRIT_BRANCH" == "master" ]; then - RTD_BUILD_VERSION=latest -else - RTD_BUILD_VERSION="${GERRIT_BRANCH/\//-}" +# Ensure we fail the job if any steps fail. +# DO NOT set -u as we depend on unbound variables being passed by Jenkins. +set -e -o pipefail + +# Ensure RTD_BUILD_URL retains the trailing slash as it is needed for the API +last_char=${RTD_BUILD_URL:length-1:1} +[[ $last_char != "/" ]] && RTD_BUILD_URL="$RTD_BUILD_URL/"; : + +json=$(curl -X POST -d "branches=${GERRIT_BRANCH}" -d "token=$RTD_TOKEN" "$RTD_BUILD_URL") +build_triggered=$(echo $json | jq -r .build_triggered) + +if [ "$build_triggered" != "true" ]; then + echo "ERROR: Build was not triggered." + echo "$json" | jq -r + exit 1 fi -curl -X POST --data "version_slug=$RTD_BUILD_VERSION" "https://readthedocs.org/build/$RTD_PROJECT" +echo "Build triggered for $GERRIT_PROJECT in ReadTheDocs."