Issue
I need to build two Maven projects which are available on Github. The first project produces a library which is needed by the second.
What is the recommended option to do it in Jenkins ?
Create a shell script which checkout and build both projects (in the correct order).
Use a pipeline ?
If you could provide any example/ relevant link that would be great. Thanks
Solution
You can achieve using 2 (upto my knowledge) options. Lets consider project A which builds libraries and project B is the dependent. I described below two options by considering two constraints.
- Project B should be built whenever Project A is built
- Project B can also be built alone if there is only changes with Project B but not with A
Option 1: You have to create two "Maven Build jobs" for Project A & B. In Project B, you have to specify "Build whenever a SNAPSHOT dependency is built" under "Build Triggers".
This only applies when project B pom.xml has dependency of Project A built artifacts and the artifacts are SNAPSHOT. Below is the image of the same.
Options 2: You can create two Freestyle job for both Project A & B. Define Project B is downstream for Project A ( It can also be done vice versa ) using "Build Other Projects" under "Post-Build Options" of Project A.
And you can copy artifacts from Project A to Project B using Copy Artifact Plugin
Exception: Ideally the above step is not necessary, if your Project A artifacts are installed on $HOME/.m2/repository
and Project B dependency defined in pom.xml (or) both project A & B are using Private Maven Repository option.
Assumption: I hope using single pipeline, it will be hard to manage this scenario. Though I expect somebody else will write with pipeline example to enlighten me as well :)
Answered By - Fidel
Answer Checked By - Timothy Miller (JavaFixing Admin)