简体   繁体   中英

Pull jobs directory from a repository into Jenkins from a Dockerfile

I am trying to create a Jenkins image that pulls a directory from a private repository that contains some preconfigured jobs and have these jobs appear on the dashboard. I made a Dockerfile that will build a Jenkins image that could pull a directory from my private repo into the Jenkins container.

However, these pulled jobs does not appear in /var/jenkins_home/jobs and so Jenkins does not show the jobs on the dashboard.

This is the general content of the Dockerfile:

FROM jenkins:latest

ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false

USER root
RUN mkdir -p /var/jenkins_home/jobs/
WORKDIR /var/jenkins_home/jobs/
RUN "pull jobs directory from here" \
    ls -lah;
WORKDIR /
USER jenkins

When I do pull the jobs directory, I have been able to pull it into only /var , but not in the /var/jenkins_home/ or the /var/jenkins_home/jobs directory.

I suspect the problem has to do with the way in which directories are created in a Jenkins image, where the /var/jenkins_home directory is being overwritten at some point in building the image.

I have a checked a related post here , but I do not want to bind any local folders with the image folders. But the idea is closely related.

Thanks you for your time.

the base Dockerfile is setting up /var/jenkins_home as a volume via this instruction:

VOLUME /var/jenkins_home

that makes this directory act differently than a normal directory in your image, with the result that you cannot write to this directory in your Dockerfile, as you attempt to do when you're pulling in your preconfigured jobs.

the problem is described in more detail in a post called Docker In-depth: Volumes , but the TLDR; is this:

FROM debian:jessie
VOLUME /foo/bar
RUN touch /foo/bar/baz
# /foo/bar/baz doesn't exist

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM