2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Linux Foundation and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
14 # Job Number Formatter
17 if [ $NUMS == 1 ]; then
24 # Activiate the virtualenv so we have access to 'jenkins-jobs'
25 source /opt/virtualenv/jenkins-job-builder/bin/activate
27 echo "> Generating list of current JJB jobs..."
28 jenkins-jobs -l ERROR test -r jjb -o job_output
30 echo "> Generating list of previous JJB jobs..."
31 git checkout -b previous-commit HEAD^
32 jenkins-jobs -l ERROR test -r jjb -o job_output_prev
33 git checkout - && git branch -d previous-commit
35 echo "> Finding job changes ..."
36 diff -r -q job_output job_output_prev &> job_diff.txt || true
38 # Only in (job_output) = NEW
39 # Only in (job_output_prev) = DELETED
40 # Files ... differ = MODIFIED
42 declare -a JOBS_ADDED=($(grep 'job_output:' job_diff.txt | cut -d':' -f2- | sed 's/^[ \t]*//;s/[ \t]*$//'))
43 declare -a JOBS_MODIFIED=($(grep 'differ$' job_diff.txt | sed "s/Files job_output\/\(.*\) and.*/\1/g"))
44 declare -a JOBS_REMOVED=($(grep 'job_output_prev:' job_diff.txt | cut -d ':' -f2- | sed 's/^[ \t]*//;s/[ \t]*$//'))
46 NUM_JOBS_ADDED=${#JOBS_ADDED[@]}
47 NUM_JOBS_MODIFIED=${#JOBS_MODIFIED[@]}
48 NUM_JOBS_REMOVED=${#JOBS_REMOVED[@]}
50 echo "> Writing gerrit comment ..."
51 if [ $NUM_JOBS_ADDED -gt 0 ]; then
52 JOB_STRING="$(JOBS $NUM_JOBS_ADDED)"
53 { printf "Added %s %s:\n\n" "${NUM_JOBS_ADDED}" "$JOB_STRING";
54 printf '* %s\n' "${JOBS_ADDED[@]}";
55 printf "\n"; } >> gerrit_comment.txt
58 if [ $NUM_JOBS_MODIFIED -gt 0 ]; then
59 JOB_STRING="$(JOBS $NUM_JOBS_MODIFIED)"
60 { printf "Modified %s %s:\n\n" "${NUM_JOBS_MODIFIED}" "$JOB_STRING";
61 printf '* %s\n' "${JOBS_MODIFIED[@]}";
62 printf "\n"; } >> gerrit_comment.txt
65 if [ $NUM_JOBS_REMOVED -gt 0 ]; then
66 JOB_STRING="$(JOBS $NUM_JOBS_REMOVED)"
67 { printf "Removed %s %s:\n\n" "${NUM_JOBS_REMOVED}" "$JOB_STRING";
68 printf '* %s\n' "${JOBS_REMOVED[@]}";
69 printf "\n"; } >> gerrit_comment.txt