-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins-entrypoint
51 lines (41 loc) · 1.67 KB
/
jenkins-entrypoint
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
#!/bin/bash
set -eo pipefail
mkdir -p ${HOME}/.ssh
# If not already present, we generate a ssh key pair to be used in the SSH connection with the agent.
if [ ! -f "${HOME}"/.ssh/id_rsa ]; then
echo "No keys present. Creating SSH Key Pair..."
eval `ssh-agent -s` \
&& ssh-keygen -q -t rsa -b 4096 -f "${HOME}"/.ssh/id_rsa -N "" <<< y \
&& echo "" \
&& echo "-- [[ Copy this pub ssh key to add it as a Jenkins Credential!]] --" \
&& echo "" \
&& cat "${HOME}"/.ssh/id_rsa.pub \
&& echo "" \
&& echo "^^^ This pub key should be added to the SSH Agent and to the ACSF job with jenkins username ^^^"
fi
# We append jenkins pub key as entry in the authorized_keys.
cat ${HOME}/.ssh/id_rsa.pub > "${HOME}"/.ssh/authorized_keys
# We check if keys are not already present, if not, we add them to known hosts.
#ssh-keygen -R jenkins.ssh-agent
HOSTS=("jenkins.ssh-agent" "jenkins.qa-agent-1" "jenkins.qa-agent-2" "jenkins.qa-agent-3" "jenkins.qa-agent-4")
for h in "${HOSTS[@]}"
do
if [[ "" == $(ssh-keygen -H -F "$h") ]]; then
echo "Key is not present! Adding remote machine ($h) to known_hosts";
ssh-keyscan -H $h >> ${HOME}/.ssh/known_hosts
else
echo "Nothing to do, $h is already in known_hosts file :)"
fi
# ssh-keygen -R $h
# echo "$h was removed from knonw_hosts"
done
# Add github.com key to known hosts
if [[ "" == $(ssh-keygen -H -F github.com) ]]; then
echo "Github rsa key not present, adding it to known hosts."
ssh-keyscan -H github.com >> ${HOME}/.ssh/known_hosts
else
echo "Nothing to do, github.com is already in known_hosts file :)"
fi
echo "Launching Jenkins..."
# We finally run the original script.
/usr/local/bin/jenkins.sh