Reputation: 670
These is a simplified maven multiple-module project, the project structure is listed below:
-pom.xml
-eureka
-src
-pom.xml
-gateway
-src
-pom.xml
-order
-src
-pom.xml
-user
-src
-pom.xml
the jenkin pipelines to start these modules are quite similar to each other, so I create this jenkins pipeline project.
The struture is list below:
-vars
-springCloudPipeline.groovy
-eureka-JenkinsFile
-gateway-JenkinsFile
-order-JenkinsFile
-user-JenkinsFile
eureka-JenkinsFile
@Library('springCloudPipeline') _
springCloudPipeline(branch :'master',
scmUrl : 'https://github.com/wuxudong/spring-cloud-best-practice.git',
serviceName : 'eureka')
gateway-JenkinsFile
@Library('springCloudPipeline') _
springCloudPipeline(branch :'master',
scmUrl : 'https://github.com/wuxudong/spring-cloud-best-practice.git',
serviceName : 'gateway')
......
vars/springCloudPipeline.groovy
def call(Map pipelineParams) {
pipeline {
agent any
environment {
branch = "${pipelineParams.branch}"
scmUrl = "${pipelineParams.scmUrl}"
serviceName = "${pipelineParams.serviceName}"
}
stages {
stage('checkout git') {
steps {
git branch: branch, url: scmUrl
}
}
stage('build') {
steps {
sh 'mvn clean package -DskipTests=true'
}
}
stage('deploy'){
steps {
sh "JENKINS_NODE_COOKIE=dontKillMe nohup java -jar ${pipelineParams.serviceName}/target/${pipelineParams.serviceName}.jar &"
}
}
}
}
}
I create 4 pipeline tasks: eureka
, gateway
, order
, user
.
the only difference is they have different script path.
In order to import springCloudPipeline template, I have to define a global pipeline library in jenkins->System Setting: springCloudPipeline -> https://github.com/wuxudong/multiple-module-jenkins-pipeline.git
because springCloudPipeline is only used by this project itself, I wonder if there is a way without define a global pipleline library.
I do find a plugin https://github.com/karolgil/SharedLibrary that can load parts of repository as shared libraries, but I wonder if there is any other offical solution?
Upvotes: 2
Views: 1903
Reputation: 508
I am wondering, why we need multiple Jenkinsfile (one for each module)?
We need to keep only one Jenkinsfile at root level and trigger the maven build from root level only. All the child module will be built/deployed reclusively.
In case you want to build/push Docker image for each module, you can trigger separately from root Jenkisfile by defining individual stages.
Upvotes: 1