Resolve several issues with dynamic stages.
This commit is contained in:
parent
1f0749b24c
commit
a261f8fec5
|
@ -40,6 +40,28 @@ echo "Use settings file at ${maven_settings_file}"
|
||||||
echo "Use local repo at ${maven_local_repo_path}"
|
echo "Use local repo at ${maven_local_repo_path}"
|
||||||
echo "Release number: ${params.gCube_release_number}"
|
echo "Release number: ${params.gCube_release_number}"
|
||||||
|
|
||||||
|
def apps = ['SmartGears':['maven-parent', 'gcube-bom', 'gxRest'],
|
||||||
|
'Enabling':['job4', 'job5', 'job6'],
|
||||||
|
'Data':['job7', 'job8', 'job9']]
|
||||||
|
def dynamicStages = [:]
|
||||||
|
|
||||||
|
//let's build the stages closures
|
||||||
|
apps.each { entry -> echo "App name: $entry.key = Jobs: $entry.value" }
|
||||||
|
apps.each { entry ->
|
||||||
|
def app = entry.key
|
||||||
|
dynamicStages["stage-${app}"] = ["${app}":{
|
||||||
|
node {
|
||||||
|
stage("Build ${app}") {
|
||||||
|
for (int j = 0; j < entry.value.size(); j++) {
|
||||||
|
build "${entry.value[j]}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Configured dynamic stages: ${dynamicStages.inspect()}"
|
||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
// see https://jenkins.io/doc/book/pipeline/syntax/#agent
|
// see https://jenkins.io/doc/book/pipeline/syntax/#agent
|
||||||
agent {
|
agent {
|
||||||
|
@ -78,37 +100,32 @@ pipeline {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('build core components') {
|
stage('Build Components') {
|
||||||
steps {
|
stages {
|
||||||
withMaven(jdk: "${maven_jdk}", mavenLocalRepo: "${maven_local_repo_path}", mavenSettingsFilePath: "${maven_settings_file}") {
|
stage('Build SmartGears components') {
|
||||||
build 'maven-parent'
|
steps {
|
||||||
build 'gcube-bom'
|
script {
|
||||||
build 'authorization-common-library'
|
parallel dynamicStages['stage-SmartGears']
|
||||||
build 'gxRest'
|
}
|
||||||
}
|
}
|
||||||
echo "Done with core components"
|
}
|
||||||
|
stage('Build enabling components') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
parallel dynamicStages['stage-Enabling']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build data components') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
parallel dynamicStages['stage-Data']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// post-build actions
|
|
||||||
post {
|
|
||||||
always {
|
|
||||||
echo 'This will always run'
|
|
||||||
}
|
|
||||||
success {
|
|
||||||
echo 'This will run only if successful'
|
|
||||||
}
|
|
||||||
failure {
|
|
||||||
echo 'This will run only if failed'
|
|
||||||
}
|
|
||||||
unstable {
|
|
||||||
echo 'This will run only if the run was marked as unstable'
|
|
||||||
}
|
|
||||||
changed {
|
|
||||||
echo 'This will run only if the state of the Pipeline has changed'
|
|
||||||
echo 'For example, if the Pipeline was previously failing but is now successful'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,25 +40,6 @@ echo "Use settings file at ${maven_settings_file}"
|
||||||
echo "Use local repo at ${maven_local_repo_path}"
|
echo "Use local repo at ${maven_local_repo_path}"
|
||||||
echo "Release number: ${params.gCube_release_number}"
|
echo "Release number: ${params.gCube_release_number}"
|
||||||
|
|
||||||
def apps = ['stage1':['job1', 'job2', 'job3'],
|
|
||||||
'stage2':['job4', 'job5', 'job6'],
|
|
||||||
'stage3':['job7', 'job8', 'job9']]
|
|
||||||
def dynamicStages = [:]
|
|
||||||
|
|
||||||
//let's build the stages closures
|
|
||||||
for (int i = 0; i < apps.size(); i++) {
|
|
||||||
def app = apps[i]
|
|
||||||
dynamicStages["stage-${app}"] = ["${app}":{
|
|
||||||
node {
|
|
||||||
stage("Build ${app}") {
|
|
||||||
for (int j = 0; j < app.size(); j++) {
|
|
||||||
build "${app[j]}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
// see https://jenkins.io/doc/book/pipeline/syntax/#agent
|
// see https://jenkins.io/doc/book/pipeline/syntax/#agent
|
||||||
agent {
|
agent {
|
||||||
|
@ -97,32 +78,37 @@ pipeline {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Build Components') {
|
stage('build core components') {
|
||||||
stages {
|
steps {
|
||||||
stage('Build SmartGears components') {
|
withMaven(jdk: "${maven_jdk}", mavenLocalRepo: "${maven_local_repo_path}", mavenSettingsFilePath: "${maven_settings_file}") {
|
||||||
steps {
|
build 'maven-parent'
|
||||||
script {
|
build 'gcube-bom'
|
||||||
parallel dynamicStages['stage-SmartGears']
|
build 'authorization-common-library'
|
||||||
}
|
build 'gxRest'
|
||||||
}
|
}
|
||||||
}
|
echo "Done with core components"
|
||||||
stage('Build enabling components') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
parallel dynamicStages['stage-Enabling']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Build data components') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
parallel dynamicStages['stage-Data']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// post-build actions
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
echo 'This will always run'
|
||||||
|
}
|
||||||
|
success {
|
||||||
|
echo 'This will run only if successful'
|
||||||
|
}
|
||||||
|
failure {
|
||||||
|
echo 'This will run only if failed'
|
||||||
|
}
|
||||||
|
unstable {
|
||||||
|
echo 'This will run only if the run was marked as unstable'
|
||||||
|
}
|
||||||
|
changed {
|
||||||
|
echo 'This will run only if the state of the Pipeline has changed'
|
||||||
|
echo 'For example, if the Pipeline was previously failing but is now successful'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue