Reputation: 551
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
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
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