How to get displayName for working with Jenkins multi-channel pipeline

I put all my Jenkins logic in a structured script pipeline (also known as Jenkinsfile).

If something goes wrong, I send letters. For the subject, I want to use displayNametasks, not task identifiers env.JOB_NAME(since they are controlled by access control and non-readability patterns).

With a normal pipelined job, I could use currentBuild.rawBuild.project.displayName, but for multi-channel pipelines, it's just the name of a branch.

Or is there an even better way to get the username and then switch to rawBuild?

+4
source share
1 answer

api, , , :

String getDisplayName(currentBuild) {
    def project = currentBuild.rawBuild.project

    // for multibranch pipelines
    if (project.parent instanceof WorkflowMultiBranchProject) {
        return "${project.parent.displayName} (${project.displayName})"
    } else {
        // for all other projects
        return project.displayName
    }
}
+5

Source: https://habr.com/ru/post/1675727/


All Articles