0

I have jenkins installed and running in a remote machine. Planned to move this complete setup to container environment, so took the complete backup of JENKINS_HOME directory of the remote machine to my local machine(/home/mohan/jenkins) and mapped this directory to container JENKINS_HOME directory for retaining the jobs, logs while running as container.

In the remote installation, have changed IP address in certain xml files like below for changing themes etc.

hudson.tasks.Mailer.xml

<?xml version='1.1' encoding='UTF-8'?>
<hudson.tasks.Mailer_-DescriptorImpl plugin="mailer@1.23">
  <hudsonUrl>http://62.221.34.56:8080/</hudsonUrl>
  <useSsl>false</useSsl>
  <charset>UTF-8</charset>
</hudson.tasks.Mailer_-DescriptorImpl>

jenkins.model.JenkinsLocationConfiguration.xml

<?xml version='1.1' encoding='UTF-8'?>
<jenkins.model.JenkinsLocationConfiguration>
  <adminAddress>mohanonrace@gmail.com</adminAddress>
  <jenkinsUrl>http://62.221.34.56:8080/</jenkinsUrl>
</jenkins.model.JenkinsLocationConfiguration>

org.codefirst.SimpleThemeDecorator.xml

<?xml version='1.1' encoding='UTF-8'?>
<org.codefirst.SimpleThemeDecorator plugin="simple-theme-plugin@0.5.1">
  <elements>
    <org.jenkinsci.plugins.simpletheme.CssUrlThemeElement>
      <url>http://62.221.34.56:8080/userContent/layout/jenkins-material-theme_1.css</url>
    </org.jenkinsci.plugins.simpletheme.CssUrlThemeElement>
  </elements>
</org.codefirst.SimpleThemeDecorator>

Dockerfile snippet:

From centos:latest
USER root
RUN curl --silent --location http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo |  tee /etc/yum.repos.d/jenkins.repo
RUN wget http://updates.jenkins-ci.org/latest/jenkins.war
COPY /home/mohan/jenkins/ /var/lib/jenkins/
ENV JENKINS_HOME=/var/lib/jenkins
COPY runjenkins.sh /runjenkins.sh
ENTRYPOINT ["sh", "runjenkins.sh"]

Docker run:

docker run -v /home/mohan/jenkins:/var/lib/jenkins mohan/jenkins-run:1.0

Because of the above volume mapping, url for themes and other still points to the old machine.

Currently changing this IP address manually in manage jenkins page for each container run.

Also tried this line in docker file to change IP address to container address:

RUN find /var/lib/jenkins/ -type f -name '*.xml' | xargs sed -i -e "s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/$(awk 'END {print $1}' /etc/hosts)/g"
COPY runjenkins.sh /runjenkins.sh
ENTRYPOINT ["sh", "runjenkins.sh"]

Above line configure the IP address in xml files based on the container IP address, but the IP address changes immediately after the container run because of the volume mapping.

Is there way to configure IP address based on the container IP address on each container run and also retains logs, jobs, plugin datas?

Thanks,

Mohan

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.