Fix unescaped * in if-statement
[releng/global-jjb.git] / shell / jjb-deploy-job.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 # Push a job to jenkins-sandbox via Gerrit / GitHub comment
12 # Comment Pattern: jjb-deploy JOB_NAME
13 # JOB_NAME: Can also include * wildcards too. Additional parameters are ignored.
14 echo "---> jjb-deploy-job.sh"
15
16 # Ensure we fail the job if any steps fail.
17 set -e -o pipefail
18
19 # shellcheck source=/tmp/v/jenkins-job-builder/bin/activate disable=SC1091
20 source "/tmp/v/jenkins-job-builder/bin/activate"
21
22 echo "-----> Fetching project"
23 git fetch origin "$GERRIT_REFSPEC" && git checkout FETCH_HEAD
24
25 # If not Gerrit Trigger than assume GitHub
26 COMMENT="${GERRIT_EVENT_COMMENT_TEXT:-$ghprbCommentBody}"
27 JOB_NAME=$(echo "$COMMENT" | grep jjb-deploy | awk '{print $2}')
28
29 # Strip all * characters to prevent pushing all jobs to Jenkins
30 if [ -z "${JOB_NAME//\*/}" ]; then
31     echo "ERROR: JOB_NAME cannot be empty or '*'."
32     exit 1
33 fi
34
35 jenkins-jobs update --recursive --workers 4 jjb/ "$JOB_NAME"