-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·140 lines (123 loc) · 2.43 KB
/
update.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
#!/bin/bash
WORKSPACE=$(pwd)
JENKINS_URL="http://jenkins.lip6.fr"
JENKINS_JOBS="antidote,riak_test,ft_antidote"
COMMIT_MSG=$(date)
is_java=0
is_git=0
is_jenkins_cli=0
is_auth=0
if type "java" > /dev/null 2>&1 ; then
is_java=1
# java -version
fi
if type "git" > /dev/null 2>&1 ; then
is_git=1
# git --version
fi
function clean_old_logs()
{
if [ -d $WORKSPACE/ft_bin ]; then
echo "Clearing old bin files ..."
rm -rf $WORKSPACE/ft_bin/*.*
else
echo "Creating bin dir ..."
mkdir $WORKSPACE/ft_bin
fi
}
function get_jenkins_cli()
{
if [ "$is_java" -eq 0 ]
then
echo "Java not found ..."
echo "jenkins-cli need java ..."
else
if [ -f $WORKSPACE/ft_bin/jenkins-cli.jar ]
then
echo "jenkins-cli found ..."
is_jenkins_cli=1
else
echo "jenkins-cli not found ..."
is_jenkins_cli=0
echo "Downloading ..."
cd $WORKSPACE/ft_bin/
wget $JENKINS_URL/jnlpJars/jenkins-cli.jar > /dev/null 2>&1
cd $WORKSPACE
fi
fi
}
function jenkins-cli_run()
{
if [ "$is_java" -eq 1 ] && [ "$is_jenkins_cli" -eq 1 ]
then
java -jar $WORKSPACE/ft_bin/jenkins-cli.jar -s $JENKINS_URL/ $@
fi
}
function check_jenkins_auth()
{
is_auth=$(jenkins-cli_run who-am-i | grep "authenticated" | wc -l)
if [ "$is_auth" -eq 1 ]
then
echo "The jenkins is authanticated ..."
else
echo "The jenkins is not authaticated ($is_auth) ..."
is_auth=0
fi
}
function get_all_jobs()
{
if [ "$is_auth" -eq 1 ]
then
for temp_jobs in $(echo $JENKINS_JOBS | sed "s/,/ /g")
do
echo "Getting XML configuration for $temp_jobs ..."
jenkins-cli_run get-job $temp_jobs > $WORKSPACE/$temp_jobs/job.xml
done
else
exit 1
fi
}
function get_plugins()
{
if [ "$is_auth" -eq 1 ]
then
echo "Getting list of plugins ..."
jenkins-cli_run list-plugins > $WORKSPACE/list-plugins.txt
else
exit 1
fi
}
function git_commit()
{
if [ "$is_git" -eq 1 ]
then
for temp_file in $(git diff --name-only)
do
echo "Commiting $temp_file in git ..."
git commit -m"$COMMIT_MSG" $temp_file
done
else
exit 1
fi
}
function git_push()
{
if [ "$is_git" -eq 1 ]
then
echo "Pusing chnages to git ..."
git push
else
exit 1
fi
}
### MAIN ###
clean_old_logs
until [ $is_jenkins_cli -eq 1 ]
do
get_jenkins_cli
done
check_jenkins_auth
get_all_jobs
get_plugins
git_commit
git_push