Chore: Upgrade Jenkins-job-builder to 6.3.0
[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 # Calls cURL to trigger a build in RTD via the Generic API
12 #
13 # Parameters:
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 # Handle case for gerrit event type is ref-updated when new tag are pushed
31 [[ $GERRIT_EVENT_TYPE =~ "ref-updated" ]] && GERRIT_BRANCH=${GERRIT_REFNAME##*/}
32
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)
36
37 if [ "$build_triggered" != "true" ]; then
38     echo "ERROR: Build was not triggered, ReadTheDocs response follows:"
39     echo "$json"
40     exit 1
41 fi
42
43 echo "Build triggered for $GERRIT_PROJECT in ReadTheDocs."
44 echo "---> rtd-trigger-build.sh ends"