-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins_allowed_commands.sh
executable file
·182 lines (165 loc) · 5.88 KB
/
jenkins_allowed_commands.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
THIS_SCRIPT=$(basename "$0")
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
function reject_command() {
echo "Command rejected by $THIS_SCRIPT: $SSH_ORIGINAL_COMMAND"
logger -t automation -p local0.info "Command rejected by $THIS_SCRIPT for user $USER: $SSH_ORIGINAL_COMMAND"
}
function pull_repo() {
cd "$1" || return
git checkout "$2"
git pull
echo "Pulled repo $1 on branch $2"
}
function disk_space_monitor() {
pull_repo cit_scripts master
bash Jenkins_diskSpaceMonitor.sh
}
function disk_space_monitor_mini() {
pull_repo cit_scripts master
bash Jenkins_diskSpaceMonitorMini.sh
}
function genpipes_full() {
pull_repo cit_scripts master
echo "running GenPipes Full on **** $HOSTNAME ****"
args="${SSH_ORIGINAL_COMMAND#*GenPipes_Full }"
cluster="$(echo "$args" | cut -d " " -f 1)"
if [[ $cluster == "graham" ]]; then
path="/project/6002326/C3G/projects/jenkins_tests"
elif [[ $cluster == "cedar" ]]; then
path="/project/6007512/C3G/projects/jenkins_tests"
elif [[ $cluster == "narval" ]]; then
path="/lustre03/project/6007512/C3G/projects/jenkins_tests"
elif [[ $cluster == "beluga" ]]; then
path="/lustre03/project/6007512/C3G/projects/jenkins_tests"
fi
branch="$(echo "$args" | cut -d " " -f 2)"
options="$(echo "$args" | cut -d " " -f 3)"
cd "$(realpath "$path")" || return
bash ./cleanup_old
# shellcheck disable=SC2086
$SCRIPT_DIR/integration_tests.sh -b ${branch} $options
}
function genpipes_update() {
pull_repo cit_scripts master
args="${SSH_ORIGINAL_COMMAND#*GenPipes_dev_update }"
cluster="$(echo "$args" | cut -d " " -f 1)"
if [[ $cluster == "graham" ]]; then
path="/project/6002326/C3G/projects/jenkins_tests"
elif [[ $cluster == "cedar" ]]; then
path="/project/6007512/C3G/projects/jenkins_tests"
elif [[ $cluster == "narval" ]]; then
path="/lustre03/project/6007512/C3G/projects/jenkins_tests"
elif [[ $cluster == "beluga" ]]; then
path="/lustre03/project/6007512/C3G/projects/jenkins_tests"
fi
branch="$(echo "$args" | cut -d " " -f 2)"
latest=$(find "$path" -maxdepth 1 -type d -name "GenPipesFull_${branch}*" | sort | tail -n 1)
options="$(echo "$args" | cut -d " " -f 3)"
cd "${latest}/genpipes" || return
git pull
cd ../..
# shellcheck disable=SC2086
$SCRIPT_DIR/integration_tests.sh -d ${latest}/genpipes ${latest}/scriptTestOutputs -u $options
}
function genpipes_command() {
pull_repo cit_scripts master
bash Jenkins_GenpipesCommands.sh
}
function update_cache() {
args="${SSH_ORIGINAL_COMMAND#*cvmfs_cache_update }"
cluster="$(echo "$args" | cut -d " " -f 1)"
if [[ $cluster == "narval" ]]; then
/project/def-bourqueg/LMOD_CACHE/update_cache.sh
elif [[ $cluster == "beluga" ]]; then
/lustre03/project/6002326/poq/lmod_caching/update_cache.sh
fi
}
function moh_genpipes() {
pull_repo moh_automation main
bash jenkins_genpipes.sh "$(${SSH_ORIGINAL_COMMAND#*MoH_GenPipes } | tr -d '\"')"
}
function moh_wrapper() {
pull_repo moh_automation main
bash jenkins_wrapper.sh
}
function check_genpipes() {
pull_repo moh_automation main
timestamp=$(date "+%Y-%m-%dT%H.%M.%S")
args="${SSH_ORIGINAL_COMMAND#*MoH_check_GenPipes }"
cluster="$(echo "$args" | cut -d " " -f 1)"
if [[ $cluster == "abacus" ]]; then
path="/lb/project/mugqic/projects/MOH/MAIN"
elif [[ $cluster == "beluga" ]]; then
path="/lustre03/project/6007512/C3G/projects/MOH_PROCESSING/MAIN"
elif [[ $cluster == "cardinal" ]]; then
path="/project/def-c3g/MOH/MAIN"
fi
logs_folder="$path/check_genpipes_logs/$timestamp"
mkdir -p "$logs_folder"
log_file="$logs_folder/check_genpipes_$timestamp.log"
cat /dev/null > "$log_file"
folder_to_be_checked=$(find "$path/genpipes_submission" -mindepth 1 -maxdepth 1 -type d '!' -exec test -e "{}.checked" ';' -print)
for folder in $folder_to_be_checked; do
json=$(find "$folder" -lname "*.json")
job_list=$(find "$folder" -lname "*job_list*")
readset=$(find "$folder" -lname "*readset.tsv")
missing_files=""
if [[ -z $json ]]; then
missing_files+="json "
fi
if [[ -z $readset ]]; then
missing_files+="readset "
fi
if [[ -z $job_list ]]; then
missing_files+="job_list "
fi
if [[ -n $missing_files ]]; then
echo "WARNING: Missing files ($missing_files) in $folder. Skipping..." 2>&1 | tee -a "$log_file"
else
# shellcheck disable=SC2086
bash check_GenPipes.sh -c $cluster -j $json -r $readset -l $job_list 2>&1 | tee -a "$log_file"
fi
done
failures=$(grep "Failure found in " "$log_file" | awk -F'Cf. ' '{print $2}' | xargs grep --no-filename "FAILED" | awk -F'\t' '{print $9}')
if [[ -n $failures ]]; then
echo "$failures" > "$logs_folder/check_genpipes_$timestamp.err"
fi
transfers=$(grep "Transferring GenPipes run" "$log_file" | awk -F'run ' '{print $2}' | sed 's/\.\.\.//g')
if [[ -n $transfers ]]; then
echo "$transfers" > "$logs_folder/check_genpipes_$timestamp.transfers"
fi
}
logger -t automation -p local0.info "Command called by $THIS_SCRIPT for user $USER: $SSH_ORIGINAL_COMMAND"
case "$SSH_ORIGINAL_COMMAND" in
Disk_Space_Monitor)
disk_space_monitor
;;
Disk_Space_Monitor_Mini)
disk_space_monitor_mini
;;
GenPipes_Full*)
genpipes_full
;;
GenPipes_dev_update*)
genpipes_update
;;
GenPipes_Command)
genpipes_command
;;
cvmfs_cache_update*)
update_cache
;;
MoH_GenPipes*)
moh_genpipes
;;
MoH_wrapper)
moh_wrapper
;;
MoH_check_GenPipes*)
check_genpipes
;;
*)
reject_command
;;
esac