Home > database >  How to display in a project that is called from another pipeline project in jenkins text in "Ed
How to display in a project that is called from another pipeline project in jenkins text in "Ed

Time:02-03

Hello: I have a pipeline project at Jenkins called "ProjectLaunch" that launches other projects automatically one day a week. I would like to show in "Edit Build Information" a text that says something like "ProjectCalled full launched", in the project that is called. With the pipeline I have in "ProjectLaunch" I can only get that text in its "Edit Execution Information" but not in the projects called.

My pipeline:

pipeline {
    agent any
    stages {
                                
        stage('Proyect called') {                                   
            steps{                       
                build job: 'Proyect called',string(name: "DESCRIPTION", value: "ProjectCalled full launched") ]
            }                  
        }   
                      
    }
}

In the project called in the configuration I have an Execute system Groovy script, it is this:

import hudson.model.*
def build = manager.build
def params = build.action(hudson.model.ParametersAction).getParameters()
def description = "${params.DESCRIPTION}"
echo "Setting build description to: ${description}"
build.createSummary("Build description").appendText(description, "html")

But when I launch it I get this error: Caught: groovy.lang.MissingPropertyException: No such property: manager for class: hudson1130775177255181016 groovy.lang.MissingPropertyException: No such property: manager for class: hudson1130775177255181016

Any ideas? Thank you.

CodePudding user response:

As far as I know, you can't set the build description of a downstream job from an upstream Job. Hence in your Downstream Job, you can have some logic to set the description based on the trigger.

pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                script {
                    echo 'Your second Job'
                    if(currentBuild.getBuildCauses()[0]._class == "org.jenkinsci.plugins.workflow.support.steps.build.BuildUpstreamCause") {
                        echo "This is triggered by  upstream Job"
                        currentBuild.description = "ProjectCalled full launched."
                    }

                }   
            }
        }
    }
}

CodePudding user response:

I've done the following because with Groovy I couldn't do it. I installed "Build Name and Description Setter" plugin. In the "ProjectLaunch" pipeline project, the pipeline would be more or less like this:

pipeline {
agent any
parameters{      
    string(name: "DESCRIPTION", defaultValue: "proyecto hijo lanzado por proyecto padre", description: "")
}
stages {
                            
    stage('ProjectCalled ') {                                   
        steps{                       
            build job: 'ProjectCalled ', parameters: [string(name: "DESCRIPTION", value: "ProjectCalled full launched")]
        }                  
    }   
                  
}

}

And in the ProjectCalled in settings, add a parameter, I select the plugin option Changes build description, and I write ${DESCRIPTION}.

Changes build description

Ah!, I have also created string parameter named DESCRIPTION and without value. String parameter

  • Related