Jenkins dynamic Pipeline not showing all stages in BlueOcean
Asked Answered
P

2

5

I have a Jenkins pipeline script with the key pieces shown below. Everything seems to be executing in the background but is not showing on BlueOcean.

enter image description here

Am I doing something wrong or it is some kind of bug on the UI?

def projects = [
    [name: 'API', folder: 'api-tests', repo: 'url'],
    [name: 'UI',folder: 'selenium-tests', repo: 'url']
]

// Create List of build stages to suit
def jobs = [:]

pipeline {
    agent {
        kubernetes {
            cloud "url"
            yaml """contents"""
        }
    }
    stages {
        stage('Downstream Testing') {
            steps {
                script{
                    // Set up List<Map<String,Closure>> describing the builds
                    projects.each { project ->
                        print "Adding stages for ${project.folder}"
        
                        jobs[project.name] = {
                            stage("Checkout Project") {
                                ...
                            }
                            stage("Smoke Tests") {
                                dir("${project.folder}") {
                                        container('maven') {
                                            // Run the maven build
                                            sh """mvn package test"""
                                        }
                                    }
                                }
                            }
                    }
                    
                    // Run all Nth step for all Projects in Parallel. 
                    parallel jobs
                }
            }   
        }
    }
}
Plaice answered 8/2, 2021 at 17:15 Comment(3)
what's your goal for this pipeline? are you planning to run both checkout and smoke test parallelly or parallelly run 2 stages i.e. api and ui with checkout and smoke test one after another?Carolincarolina
Each branch will have a series of stages. Each branch should run in parallel. Each branch is a different project. That's why there are checkout and tests for each.Plaice
looks like you are correct. I have added my scenario in the answer. If you just convert your declarative to scripted the UI will show correctlyCarolincarolina
C
5

Yes, It seems there is a bug in the Blueocean UI.

The scenario works fine for the scripted pipeline but the same fail in declarative pipeline

scripted pipeline

def j=[:]
node {
    [
        [name: "api", folder: "api"],
        [name: "ui", folder: "ui"]
    ].each { m -> 
        j[m.name] = {
            stage('a') {
                echo "A"
            }
            stage('b') {
                echo "B"
            }
        }
    }
    parallel j
}

enter image description here

declarative pipeline

pipeline {
    agent any;
    stages {
        stage("parallel") {
            steps {
                script {
                    def j=[:]
                    [
                        [name: "api", folder: "api"],
                        [name: "ui", folder: "ui"]
                    ].each { m -> 
                        j[m.name] = {
                            stage('a') {
                                echo "A"
                            }
                            stage('b') {
                                echo "B"
                            }
                        }
                    }
                    parallel j
                }
            }
        }
    }
}

enter image description here

Carolincarolina answered 8/2, 2021 at 18:32 Comment(2)
Created an issue for it issues.jenkins.io/browse/JENKINS-64822Plaice
I have seen exactly the same issue, we also see only the first stage.Blakley
I
2

In my project, I found a workaround for this case in declarative pipeline. Surrounding a stage for it could make the blueocean displaying well.

But the weird thing is this stage name has to equal to the key name in j.

pipeline {
    agent any;
    stages {
        stage("parallel") {
            steps {
                script {
                    def j=[:]
                    [
                        [name: "api", folder: "api"],
                        [name: "ui", folder: "ui"]
                    ].each { m -> 
                        j[m.name] = {  // key has to keep the same name as stage name
                            stage(m.name) { // keep the same name as key
                                stage('a') {
                                    echo "A"
                                }
                                stage('b') {
                                    echo "B"
                                }
                            }
                        }
                    }
                    parallel j
                }
            }
        }
    }
}

see blueocean image

Ignacia answered 18/1 at 10:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.