X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=blobdiff_plain;f=shell%2Frtd-trigger-build.sh;h=6af08d7dfebff6ca382122dd20fc8e4a1774a132;hb=dbd05cd4100a27a545cc2c7f0388018449d982c3;hp=5c47ea645ea76fdc18e584c6112be7ea14e520ba;hpb=12d6179c0e7c208a360a3c61c0b715b49310b39e;p=releng%2Fglobal-jjb.git diff --git a/shell/rtd-trigger-build.sh b/shell/rtd-trigger-build.sh index 5c47ea64..6af08d7d 100644 --- a/shell/rtd-trigger-build.sh +++ b/shell/rtd-trigger-build.sh @@ -8,24 +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" # Ensure we fail the job if any steps fail. -# DO NOT set -u -set -xe -o pipefail +# DO NOT set -u as we depend on unbound variables being passed by Jenkins. +set -e -o pipefail -if [ "$GERRIT_BRANCH" == "master" ]; then - RTD_BUILD_VERSION=latest -else - RTD_BUILD_VERSION="${GERRIT_BRANCH/\//-}" -fi - -CREDENTIAL=$(xmlstarlet sel -N "x=http://maven.apache.org/SETTINGS/1.0.0" \ - -t -m "/x:settings/x:servers/x:server[x:id='${SERVER_ID}']" \ - -v x:username -o ":" -v x:password \ - "$SETTINGS_FILE") +# 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/"; : -RTD_BUILD_TOKEN=$(echo "$CREDENTIAL" | cut -f2 -d:) +json=$(curl -X POST -d "branches=${GERRIT_BRANCH}" -d "token=$RTD_TOKEN" "$RTD_BUILD_URL") +build_triggered=$(echo "$json" | jq -r .build_triggered) -curl -X POST -d "branches=$RTD_BUILD_VERSION" -d "token=$RTD_BUILD_TOKEN" "$RTD_BUILD_URL" +if [ "$build_triggered" != "true" ]; then + echo "ERROR: Build was not triggered." + echo "$json" | jq -r + exit 1 +fi +echo "Build triggered for $GERRIT_PROJECT in ReadTheDocs."