Make sure that jjb-cleanup.sh allows unbound vars
[releng/global-jjb.git] / shell / rtd-trigger-build.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
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
12 #
13 # Paramters:
14 #     RTD_BUILD_URL: The unique build URL for the project.
15 #                    Check Admin > Integrations > Generic API incoming webhook.
16 #
17 #     RTD_TOKEN: The unique token for the project Generic webhook.
18 #                Check Admin > Integrations > Generic API incoming webhook.
19
20 echo "---> rtd-trigger-build.sh"
21
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.
24 set -e -o pipefail
25
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/"; :
29
30 json=$(curl -X POST -d "branches=${GERRIT_BRANCH}" -d "token=$RTD_TOKEN" "$RTD_BUILD_URL")
31 build_triggered=$(echo $json | jq -r .build_triggered)
32
33 if [ "$build_triggered" != "true" ]; then
34     echo "ERROR: Build was not triggered."
35     echo "$json" | jq -r
36     exit 1
37 fi
38
39 echo "Build triggered for $GERRIT_PROJECT in ReadTheDocs."