forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkins-artifacts
executable file
·50 lines (46 loc) · 1.51 KB
/
jenkins-artifacts
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
#!/bin/bash -ex
ARTIFACTS_USER=$(whoami)
if [ "$ARTIFACTS_USER" = "cmsbld" ] ; then ARTIFACTS_USER="cmsbuild" ; fi
ARTIFACTS_MACHINE=${ARTIFACTS_USER}@cmssdtprod.cern.ch
ARTIFACT_BASE_DIR=/data/sdt/SDT/jenkins-artifacts
SSH_OPTS="-o IdentitiesOnly=yes -o PubkeyAuthentication=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ServerAliveInterval=60"
function has_jenkins_artifacts ()
{
local SRC=$1
local TYPE=$2
[ "X$TYPE" = "X" ] && TYPE="-e"
ssh $SSH_OPTS ${ARTIFACTS_MACHINE} "test ${TYPE} ${ARTIFACT_BASE_DIR}/${SRC}" && echo "JA_STATUS=OK" && return 0
echo "JA_STATUS=ERROR"
return 1
}
function send_jenkins_artifacts ()
{
local SRC=$1
local DES=$2
local IS_DIR=$(test -d $SRC && echo "/")
local DES_DIR=$DES
if [ "X$IS_DIR" = "X" ] ; then DES_DIR=$(dirname $DES) ; fi
for i in 1 2 3 4 5 ; do
( ssh $SSH_OPTS ${ARTIFACTS_MACHINE} mkdir -p ${ARTIFACT_BASE_DIR}/${DES_DIR} && \
rsync -az -e "ssh $SSH_OPTS" ${SRC}${IS_DIR} ${ARTIFACTS_MACHINE}:${ARTIFACT_BASE_DIR}/${DES_DIR}${IS_DIR} && echo "JA_STATUS=OK") && return
sleep 120
done
echo "JA_STATUS=ERROR"
return 1
}
function get_jenkins_artifacts ()
{
local SRC=$1
local DES=$2
case $SRC in
*/) mkdir -p $DES ; DES="${DES}/";;
* ) mkdir -p $(dirname $DES) ;;
esac
has_jenkins_artifacts $1 || return 1
for i in 1 2 3 4 5 ; do
rsync -az -e "ssh $SSH_OPTS" ${ARTIFACTS_MACHINE}:${ARTIFACT_BASE_DIR}/${SRC} ${DES} && echo "JA_STATUS=OK" && return
sleep 120
done
echo "JA_STATUS=ERROR"
return 1
}