javajenkins-pipelinedocker-buildmultibranch-pipelinecontainer-image

two java repositories one with dependency code and the other with the application code, how do i containerise this app?


Here is my question or problem I am facing in detail.

I have two git repositories which have multiple branches, dev branches and master, first is a java application(repo1) and the other java repository that creates dependency jars(repo2) in ".m2" directory after "mvn clean install", for repo1 to be successfully built jars from repo2 are required which then can be deployed in tomcat.

I want to containerise this application in repo1. I have created the dockerfile which can build the application if there are both repositories in the context directory and create a docker image that can be deployed.

But the problem is I am unable to create a Jenkins job which can pull both repositories when there is any change in either of them and trigger the build.

I've tried a pipeline job which can take in a jenkinsfile, it polls both SCMs and triggers the job if there is a change in either of the repos, but it can only be done for a single branch. As I meantioned earlier I have multiple branches and I can't create a job for each one of those branches and cretae more whenever there is a new branch, because of it this is not a feasible option.

I've also tried a multibranch job, this will build for multiple branches but it can only check for changes in only one repo since it is not built for checking different code bases but multiple repositories with same code base(it's a different topic). The take from this was it will not check for the changes in both repositories.

What I am looking for is a setup which will check for any change in all branches of both repositories and if found trigger a build that will pull changes and create the docker image.

So this is the issue, and I am not getting any solution for this problem. Please let me know if anyone had the same issue and found a solution.

PS: I hope the information I've given is enough and if not do let me know and I'll provide anything needed.

Thanks in advance.


Solution

  • The solution I went ahead with is building both repo1 and repo2 outside the docker, and in Dockerfile only copying the final .war and .jar files into the tomcat image. This way I don't have to worry about the dependencies from repo2 in .m2 directory, because both the repos are being built on the same host.

    But the only drawback is that if I want to run it on a different host, I must manually set up the environment like installing the maven, java, etc.