2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 # Call cURL to trigger a build in RTD via the Generic API
14 # RTD_BUILD_URL: The unique build URL for the project.
15 # Check Admin > Integrations > Generic API incoming webhook.
17 # RTD_TOKEN: The unique token for the project Generic webhook.
18 # Check Admin > Integrations > Generic API incoming webhook.
20 echo "---> rtd-trigger-build.sh"
22 # Ensure we fail the job if any steps fail.
23 # DO NOT set -u as we depend on unbound variables being passed by Jenkins.
26 # Ensure RTD_BUILD_URL retains the trailing slash as it is needed for the API
27 last_char=${RTD_BUILD_URL:length-1:1}
28 [[ $last_char != "/" ]] && RTD_BUILD_URL="$RTD_BUILD_URL/"; :
30 # Handle case for gerrit event type is ref-updated when new tag are pushed
31 [[ $GERRIT_EVENT_TYPE =~ "ref-updated" ]] && GERRIT_BRANCH=${GERRIT_REFNAME##*/}
33 echo "INFO: Posting request for branch $GERRIT_BRANCH to URL $RTD_BUILD_URL"
34 json=$(curl -X POST -d "branches=${GERRIT_BRANCH}" -d "token=$RTD_TOKEN" "$RTD_BUILD_URL")
35 build_triggered=$(echo "$json" | jq -r .build_triggered)
37 if [ "$build_triggered" != "true" ]; then
38 echo "ERROR: Build was not triggered."
43 echo "Build triggered for $GERRIT_PROJECT in ReadTheDocs."