forked from Verigreen/jenkins-tomcat-nginx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-groovy-jobs.sh
executable file
·68 lines (56 loc) · 1.6 KB
/
build-groovy-jobs.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
#! /bin/bash
#
# Programmically Enable Jobs in Jenkins Jobs DSL Plugin
# =====================================================
#
# ## Maintainer(s)
# Jonathan Rosado Lugo
#
# ## Description:
#
# Script for triggering the seed job. The seed job is responsible for
# initializing the groovy defined jobs.
echo "Executing..."
JOB_INSTALLED="true"
function check_groovy_dsl_job {
# Wait for Jenkins to load
while ! curl -s --head --request GET http://localhost:8080/ | grep "200 OK" > /dev/null;
do
echo "Waiting for jenkins.."
done
# Wait for Jenkins to load assets
sleep 10
# Once it loads, look to see if the groovy-dsl-job persisted from a past instance
if [[ $( curl -s "http://localhost:8080" | grep /groovy-dsl-job/ ) ]]; then
echo "groovy-dsl-job was found"
else
JOB_INSTALLED="false"
echo "groovy-dsl-job was NOT found"
fi
}
check_groovy_dsl_job
while true;
do
if [[ -f "/var/tmp/jobs.groovy" ]]; then
if [[ $JOB_INSTALLED == "false" ]]; then
cp -f /var/tmp/jobs.groovy /var/tmp/groovy-dsl-job/workspace/jobs.groovy
mkdir -p /var/jenkins_home/jobs/ && \
cp -f -R /var/tmp/groovy-dsl-job/ /var/jenkins_home/jobs/groovy-dsl-job/
echo "Job installed"
JOB_INSTALLED="true"
supervisorctl restart all:jenkins
check_groovy_dsl_job
else
if [[ $(curl -s --head --request GET http://localhost:8080/job/groovy-dsl-job/build \
| grep "201 Created" ) ]]; then
echo "Seed has been built"
# Wait for the seed job to build
sleep 20
curl -s --head --request POST http://localhost:8080/job/groovy-dsl-job/doDelete
exit 0
fi
fi
else
exit 0
fi
done