Search code examples
jenkinsgroovyjenkins-pipeline

Setting pipeline description in declarative Jenkinsfile


Background

We develop our Jenkins pipeline using declarative Jenkinsfile scripts. For example, if we want to set a log rotate policy on a pipeline, we can use the options directive.

options {
    buildDiscarder( logRotator( numToKeepStr: "30" ) )
}

After we run the pipeline, we would see the following log rotate policy on the configuration screen in Jenkins

GUI log rotate policy

We never make modifications to the GUI ( such as manually configuring log rotate ), instead that should be driven by the Jenkinsfile

Question

We want to set the description on a pipeline using the Jenkinsfile. However, we do not see any closures named description. After some research we did find some ways to set description for the builds ( see below ), but not the description of the pipeline itself.

        steps {
            script {
                this.setDescription("123")
                currentBuild.displayName = "The name."
                currentBuild.description = "The best description."
            }
        }

How do we set the description of the pipeline using a directive in a Jenkinsfile?


Solution

  • You may add the below code to your groovy script, Please make sure you have installed the Project Description Setter plugin to your Jenkins

    pipeline {
        agent any
        options {
            buildDiscarder(logRotator(numToKeepStr: "30"))
        }
        properties([
            [class: 'org.jenkinsCi.plugins.projectDescriptionSetter.DescriptionSetterWrapper', description: 'I am the pipeline description']
        ])