Build a pipeline of Jenkins jobs

13 views
Skip to first unread message

Breitbach, Steffen

unread,
Jun 28, 2017, 4:34:29 AM6/28/17
to jenkins...@googlegroups.com

Hi everyone!

 

I'm trying to build a Jenkins pipeline which executes other Jenkins jobs in a particular order. I want to display each job's log in the pipeline, so here is what I've came up with so far:

 

pipeline {

    agent {

        label 'pipeline'

    }

    stages {

        stage('First') {

            steps {

                script {

                    def buildJob = ""

                    try {

                        buildJob = build job: 'First'

                    } finally {

                        println buildJob.rawBuild.log

                    }

                }

            }

        }

        stage('Second, Third') {

            steps {

                parallel (

                    "Second" : {

                        script {

                            def buildJob = ""

                            try {

                                buildJob = build job: 'Second'

                            } finally {

                                println buildJob.rawBuild.log

                            }

                        }

                    },

 

I have used the try-finally blocks so that the build log always will be displayed, regardless of the buildJob outcome.

 

Interposed question: Would it be possible to get a 'live' log output while the job is being build?

 

Anyhow, my problem is that I the second "println" will print the log of the first job if the second job fails, not the log of the second job. This is why I've added the def in the last script block, but this will yield an unclassified field java.lang.String rawBuild error.

 

How could I work around this?

 

Thanks

 

Steffen

Reply all
Reply to author
Forward
0 new messages