-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins_init_wrapper.sh
executable file
·66 lines (54 loc) · 1.86 KB
/
jenkins_init_wrapper.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
#!/bin/bash
# Read Env Vars set by Docker
source /docker.env
# Create a Jenkins default file, used by init script
cat <<EOF > /etc/default/jenkins
NAME=jenkins
JAVA=/usr/bin/java
JAVA_ARGS="${JENKINS_JAVA_ARGS}"
PIDFILE=/var/run/jenkins/jenkins.pid
JENKINS_USER=jenkins
JENKINS_WAR=/usr/share/jenkins/jenkins.war
JENKINS_HOME="${JENKINS_HOME}"
RUN_STANDALONE=true
JENKINS_LOG=/var/log/jenkins/\$NAME.log
MAXOPENFILES=${JENKINS_MAXOPENFILES}
HTTP_PORT=8080
AJP_PORT=-1
PREFIX="${JENKINS_PREFIX}"
JENKINS_ARGS="${JENKINS_ARGS}"
EOF
source /etc/default/jenkins
# Set Jenkins user password, so we can SSH
JENKINS_PASSWD=$(openssl rand -base64 6)
echo JENKINS_PASSWORD=${JENKINS_PASSWD}
echo -e "${JENKINS_PASSWD}\n${JENKINS_PASSWD}" | passwd jenkins &>/dev/null
# Allow the Jenkins user to control Monit services
usermod -G monit -s /bin/bash jenkins
mkdir -p $(dirname ${PIDFILE}) $(dirname ${JENKINS_LOG}) ${JENKINS_HOME}/plugins
chown -R jenkins ${JENKINS_HOME} $(dirname ${PIDFILE}) $(dirname ${JENKINS_LOG})
# Enable downloaded plugins
for plugin in $(find /downloaded_plugins/ -type f -name "*.[hj]pi")
do
ln -s ${plugin} ${JENKINS_HOME}/plugins/
done
# Copy default config.xml if it is non-existing
if [ ! -f ${JENKINS_HOME}/config.xml ]
then
cp /plugins_script/config.xml ${JENKINS_HOME}
fi
# Set JNLP slave port if the environment variable is set
if [ -n "${JENKINS_SLAVE_JNLP}" ]
then
sed -e "s/<slaveAgentPort>.*/<slaveAgentPort>${JENKINS_SLAVE_JNLP}<\/slaveAgentPort>/" -i ${JENKINS_HOME}/config.xml
fi
# Copy the rsa keys and add known hosts if they are non-existing
if [ ! -d ${JENKINS_HOME}/.ssh ]
then
mkdir -p -d ${JENKINS_HOME}/.ssh
ssh-keyscan -t rsa,dsa bitbucket.org > /root/.ssh/known_hosts
cp /plugins_script/jenkins_id_rsa* ${JENKINS_HOME}/.ssh
fi
ID_RSA_PUB=$(more $JENKINS_HOME/.ssh/jenkins_id_rsa.pub)
echo ID_RSA_PUB=${ID_RSA_PUB}
/etc/init.d/jenkins $1