Is not a best practice to have several apps or libraries in one git repository. I advise you to use a git repository for each project. Also don't use spaces in sub projects name.
According to your comments, you will be able to compile your artifacts with one of the follow approaches:
Parent pom
As a extremely summary, you could build several maven projects with one hit. In your case you must add one pom.xml at root.
my-git-repository
├── pom.xml
├── project-a
├── pom.xml
├── project-b
├── pom.xml
This new pom.xml must be something like this:
?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>acme.foo</groupId>
<artifactId>bar</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<dependencies>
...
</dependencies>
<modules>
<module>../project-a</module>
<module>../project-b</module>
</modules>
<!-- Build -->
<build>
...
</build>
</project>
Finally, at root execute mvn clean package
. As you will see, all the registered project in <modules>
will be compiled.
More details about maven submodules here:
dir step
You are using node in your script, so it's not a declarative pipeline in which jenkinsfile is used. You are using a scripted pipeline
No matter if you are using scripted pipeline or declarative pipeline, a step called dir is the solution
node {
stage('Build') {
git url: 'git@github.com:abc/sample.git'
dir("Project-A") {
withMaven {
sh "mvn clean package"
}
}
dir("Project-B") {
withMaven {
sh "mvn clean package"
}
}
}
}
More details about dir step and jenkins pipelines type here: