Chore: Upgrade Jenkins-job-builder to 6.3.0
[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 -uef -o pipefail
18
19 # shellcheck disable=SC1090
20 source ~/lf-env.sh
21
22 # Version controlled by JJB_VERSION
23 lf-activate-venv --python python3 --venv-file /tmp/.jjb_venv jenkins-job-builder setuptools==65.7.0
24
25 # Fetch patch if gerrit project matches the jjb-deploy project
26 if [ "${GERRIT_PROJECT}" == "${PROJECT}" ]; then
27     echo "-----> Fetching ${PROJECT} patch"
28     git fetch origin "$GERRIT_REFSPEC" && git checkout FETCH_HEAD
29     git submodule update --init --recursive
30 fi
31
32 # If not Gerrit Trigger than assume GitHub
33 COMMENT="${GERRIT_EVENT_COMMENT_TEXT:-$ghprbCommentBody}"
34 JOB_NAME=$(echo "$COMMENT" | grep jjb-deploy | awk '{print $2}')
35
36 # Strip all * characters to prevent pushing all jobs to Jenkins
37 if [ -z "${JOB_NAME//\*/}" ]; then
38     echo "ERROR: JOB_NAME cannot be empty or '*'."
39     exit 1
40 fi
41
42 echo "Deploying Job $JOB_NAME to sandbox"
43 jenkins-jobs -s sandbox update --jobs-only --recursive --workers 4 jjb/ "$JOB_NAME"