Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
While installing jenkins set the Jenkins URL to the private ip so JNLP
Browse files Browse the repository at this point in the history
works & disable reverse proxy warning
  • Loading branch information
clguiman committed Apr 14, 2017
1 parent 113c878 commit ea622e6
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions jenkins/install_jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Command
$0
Arguments
--jenkins_fqdn|-jf [Required] : Jenkins FQDN
--vm_private_ip|-pi : The VM private ip used to configure Jenkins URL. If missing, jenkins_fqdn will be used instead
--artifacts_location|-al : Url used to reference other scripts/artifacts.
--sas_token|-st : A sas token needed if the artifacts location is private.
EOF
Expand Down Expand Up @@ -34,6 +35,10 @@ do
jenkins_fqdn="$1"
shift
;;
--vm_private_ip|-pi)
vm_private_ip="$1"
shift
;;
--artifacts_location|-al)
artifacts_location="$1"
shift
Expand All @@ -54,6 +59,14 @@ done

throw_if_empty --jenkins_fqdn $jenkins_fqdn

if [ -z "$vm_private_ip" ]; then
#use port 80 for public fqdn
jenkins_url="http://${jenkins_fqdn}/"
else
#use port 8080 for internal
jenkins_url="http://${vm_private_ip}:8080/"
fi

jenkins_auth_matrix_conf=$(cat <<EOF
<authorizationStrategy class="hudson.security.ProjectMatrixAuthorizationStrategy">
<permission>com.cloudbees.plugins.credentials.CredentialsProvider.Create:authenticated</permission>
Expand Down Expand Up @@ -96,6 +109,22 @@ jenkins_auth_matrix_conf=$(cat <<EOF
EOF
)

jenkins_location_conf=$(cat <<EOF
<?xml version='1.0' encoding='UTF-8'?>
<jenkins.model.JenkinsLocationConfiguration>
<adminAddress>address not configured yet &lt;nobody@nowhere&gt;</adminAddress>
<jenkinsUrl>${jenkins_url}</jenkinsUrl>
</jenkins.model.JenkinsLocationConfiguration>
EOF
)

jenkins_disable_reverse_proxy_warning=$(cat <<EOF
<disabledAdministrativeMonitors>
<string>hudson.diagnosis.ReverseProxySetupMonitor</string>
</disabledAdministrativeMonitors>
EOF
)

nginx_reverse_proxy_conf=$(cat <<EOF
server {
listen 80;
Expand Down Expand Up @@ -143,6 +172,15 @@ inter_jenkins_config=$(sed -zr -e"s|<authorizationStrategy.*</authorizationStrat
final_jenkins_config=${inter_jenkins_config//'{auth-strategy-token}'/${jenkins_auth_matrix_conf}}
echo "${final_jenkins_config}" | sudo tee /var/lib/jenkins/config.xml > /dev/null

#set up Jenkins URL to private_ip:8080 so JNLP connections can be established
echo "${jenkins_location_conf}" | sudo tee /var/lib/jenkins/jenkins.model.JenkinsLocationConfiguration.xml > /dev/null

#disable 'It appears that your reverse proxy set up is broken' warning.
# This is visible when connecting through SSH tunneling
inter_jenkins_config=$(sed -zr -e"s|<disabledAdministrativeMonitors/>|{disable-reverse-proxy-token}|" /var/lib/jenkins/config.xml)
final_jenkins_config=${inter_jenkins_config//'{disable-reverse-proxy-token}'/${jenkins_disable_reverse_proxy_warning}}
echo "${final_jenkins_config}" | sudo tee /var/lib/jenkins/config.xml > /dev/null

#restart jenkins
sudo service jenkins restart

Expand Down

0 comments on commit ea622e6

Please sign in to comment.