Resolve several issues with dynamic stages.

This commit is contained in:
Manuele Simi 2019-08-29 15:12:50 -04:00
parent 1f0749b24c
commit a261f8fec5
2 changed files with 75 additions and 72 deletions

75
Jenkinsfile vendored
View File

@ -40,6 +40,28 @@ echo "Use settings file at ${maven_settings_file}"
echo "Use local repo at ${maven_local_repo_path}"
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 {
// see https://jenkins.io/doc/book/pipeline/syntax/#agent
agent {
@ -78,37 +100,32 @@ pipeline {
}
}
stage('build core components') {
steps {
withMaven(jdk: "${maven_jdk}", mavenLocalRepo: "${maven_local_repo_path}", mavenSettingsFilePath: "${maven_settings_file}") {
build 'maven-parent'
build 'gcube-bom'
build 'authorization-common-library'
build 'gxRest'
}
echo "Done with core components"
stage('Build Components') {
stages {
stage('Build SmartGears components') {
steps {
script {
parallel dynamicStages['stage-SmartGears']
}
}
}
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'
}
}
}

View File

@ -40,25 +40,6 @@ echo "Use settings file at ${maven_settings_file}"
echo "Use local repo at ${maven_local_repo_path}"
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 {
// see https://jenkins.io/doc/book/pipeline/syntax/#agent
agent {
@ -97,32 +78,37 @@ pipeline {
}
}
stage('Build Components') {
stages {
stage('Build SmartGears components') {
steps {
script {
parallel dynamicStages['stage-SmartGears']
}
}
}
stage('Build enabling components') {
steps {
script {
parallel dynamicStages['stage-Enabling']
}
}
}
stage('Build data components') {
steps {
script {
parallel dynamicStages['stage-Data']
}
}
}
stage('build core components') {
steps {
withMaven(jdk: "${maven_jdk}", mavenLocalRepo: "${maven_local_repo_path}", mavenSettingsFilePath: "${maven_settings_file}") {
build 'maven-parent'
build 'gcube-bom'
build 'authorization-common-library'
build 'gxRest'
}
echo "Done with core components"
}
}
}
// 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'
}
}
}