Docker Community Forums

Share and learn in the Docker community.

Confusion with jenkins on docker

I’m trying to implement docker with jenkins and am not sure if I am on the right track.

Given:
Running jenkins on docker from Windows
Plan on fetching code from github, building the solution, running functional tests, etc on a container somehow

What I’ve currently done:
(1) Installed Docker on Windows
(2) Successfully launched Jenkins on Docker with the command
“docker run –name myJenkins -p 8080:8080 -p 50000:50000 -v ~/Jenkins:/var/jenkins_home/ jenkins/jenkins:lts”
I believe this step binds the docker volume to my host machine’s directory. This allows me to view and access the Jenkins content.
(3) In my host machine’s Jenkins directory, I’ve created a plugin.txt (containing a variety of Jenkins plugins I want installed) and a Dockerfile. The Dockerfile installs the specified plugins in the plugins.txt file.

FROM jenkins/jenkins:lts
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt

(4) In the windows command prompt, I built the Dockerfile with the command “docker build -t new_jenkins_image .”
(5) I stop my current container “myJenkins” and create a new container with the command “docker run –name myJenkins2 -p 8080:8080 -p 50000:50000 -v ~/Jenkins:/var/jenkins_home/ new_jenkins_image”. This loads up Jenkins with the newly installed jenkins plugins.

What I’m stuck/confused on
(1) Do I have to create a new container with a new name every time I want to install new jenkins plugins through the Dockerfile? This seems like a manual process as well… There has to be a better way.
(2) I started a basic jenkins pipeline job with the “Pipeline script from SCM” option. I entered in the correct repository URL and credentials but left the “Script Path” blank for now (I do not have a Jenkinsfile yet). When I execute the build, Jenkins did not fetch the code from github.

java.lang.IllegalArgumentException: Empty path not permitted.
	at org.eclipse.jgit.treewalk.filter.PathFilter.create(PathFilter.java:80)
	at org.eclipse.jgit.treewalk.TreeWalk.forPath(TreeWalk.java:205)
	at org.eclipse.jgit.treewalk.TreeWalk.forPath(TreeWalk.java:249)
	at org.eclipse.jgit.treewalk.TreeWalk.forPath(TreeWalk.java:281)
	at jenkins.plugins.git.GitSCMFile$3.invoke(GitSCMFile.java:171)
	at jenkins.plugins.git.GitSCMFile$3.invoke(GitSCMFile.java:165)
	at jenkins.plugins.git.GitSCMFileSystem$3.invoke(GitSCMFileSystem.java:193)
	at org.jenkinsci.plugins.gitclient.AbstractGitAPIImpl.withRepository(AbstractGitAPIImpl.java:29)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.withRepository(CliGitAPIImpl.java:72)
	at jenkins.plugins.git.GitSCMFileSystem.invoke(GitSCMFileSystem.java:189)
	at jenkins.plugins.git.GitSCMFile.content(GitSCMFile.java:165)
	at jenkins.scm.api.SCMFile.contentAsString(SCMFile.java:338)
	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:110)
	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:67)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:293)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE

I believe it’s because the docker container does not have git installed? The container cannot access the Git or MSBuild from my host machine… Do I have to create a new container here to simply fetch the code?

Can someone explain to me what I’m missing? From my understanding, the process goes like this: Create new pipeline job -> select pipeline script from scm -> enter repo URL, credentials, branch to build and Jenkinsfile -> Jenkinsfile will execute instructions to compile, test, and deploy.
Where does the Dockerfile come into play here? Is my thought process on the right track?