-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate_job.sh
executable file
·57 lines (49 loc) · 1.76 KB
/
create_job.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
#!/usr/bin/env bash
# checking input parameters
if [ $# == 3 ] || [ $# == 4 ]; then
ROSRELEASE=$1
GITHUBUSER=$2
REPOSITORY=$3
EMAIL=$4
JOBNAME=$ROSRELEASE\_\_$GITHUBUSER\_\_$REPOSITORY
echo "Creating hudson config with"
echo "ROS release = " $ROSRELEASE
echo "Github user name = " $GITHUBUSER
echo "Github repository name = " $REPOSITORY
echo "User email = " $EMAIL
echo "Job name = " $JOBNAME
else
echo "ERROR: Wrong number of parameters"
echo "Usage: create_job.sh ROSRELEASE GITHUBUSER REPOSITORY [EMAIL]"
exit 1
fi
# checking for ROS release
if [[ "$ROSRELEASE" != "boxturtle" && "$ROSRELEASE" != "cturtle" && "$ROSRELEASE" != "diamondback" && "$ROSRELEASE" != "unstable" ]]; then
echo "ERROR: no valid ROS release specified"
exit 1
fi
# check, if job already exists
if [ -d /var/lib/hudson/jobs/$JOBNAME ]; then
read -p "Job already exists, overwriting configuration? (y/N)"
if [[ $REPLY = [yY] ]]; then
echo "Overwriting job $JOBNAME"
else
echo "Aborting..."
exit 1
fi
fi
# create new job directory
sudo mkdir -p /var/lib/hudson/jobs/$JOBNAME
# copy config file
sudo cp config.xml /var/lib/hudson/jobs/$JOBNAME/config.xml
# generate config file
sudo sed -i "s/---GITHUBUSER---/$GITHUBUSER/g" /var/lib/hudson/jobs/$JOBNAME/config.xml
sudo sed -i "s/---REPOSITORY---/$REPOSITORY/g" /var/lib/hudson/jobs/$JOBNAME/config.xml
sudo sed -i "s/---ROSRELEASE---/$ROSRELEASE/g" /var/lib/hudson/jobs/$JOBNAME/config.xml
sudo sed -i "s/---EMAIL---/$EMAIL/g" /var/lib/hudson/jobs/$JOBNAME/config.xml
sudo sed -i "s/---JOBNAME---/$JOBNAME/g" /var/lib/hudson/jobs/$JOBNAME/config.xml
# change owner to hudson
sudo chown -R hudson.hudson /var/lib/hudson/jobs
echo ""
echo "Job $JOBNAME created."
echo "Restart Hudson to include new job."