Costas
Costas

Reputation: 551

Jenkins scripted or declarative pipeline - how to set job description text

Does anyone know how to set the description text for a job defined in scripted or declarative pipeline in Jenkins ? Reason: I want to add some meaningful text (small documentation) about the job.

Upvotes: 7

Views: 4779

Answers (2)

snukone
snukone

Reputation: 332

This solution changes the description of a job item via a groovy script in jenkins. I only used it in a freestyle job, but i think it should be also working in an scripted pipeline:

import jenkins.model.*
final jenkins   = Jenkins.getInstanceOrNull()
final myJob     = jenkins.getItem("MyJobName")

description = "<h1 style=\"color:green\">The newest build has number ${env.BUILD_NUMBER}</h1>"
myJob.setDescription(description)
myJob.save()

This solution changes the description of a build: Use 'currentbuild' global variable.

I.e. declarative pipeline:

script { currentbuild.description = 'New Description' }

Works the same in scripted pipelines :)

Reference: https://opensource.triology.de/jenkins/pipeline-syntax/globals

Upvotes: 6

Mor Lajb
Mor Lajb

Reputation: 2636

for declarative pipeline

script {
       currentBuild.description = "description env var if required :${env.ver}"
}

for scripted

currentBuild.description = "description env var if required :${env.ver}"

Upvotes: 1

Related Questions