Noel Yap
Noel Yap

Reputation: 19798

How to set build description in Jenkins JobDSL?

A Build Flow Plugin script can call build.setDescription() to set the build's description. Can something similar be done in a JobDSL script? Or would the script have to go through injecting an environment variable?

Upvotes: 3

Views: 3110

Answers (1)

daspilker
daspilker

Reputation: 8194

The Build Flow Plugin and the Job DSL Plugin are not necessarily comparable, they address different use cases. The Job DSL describe the static configuration of jobs whereas the Build Flow DSL describes a dynamic flow control of jobs.

That said, the Job DSL can configure the Description Setter Plugin as a post-build action:

job {
  ...
  publishers {
    ...
    buildDescription('', '${BRANCH}')
  }
}

See the Job DSL wiki for details: https://github.com/jenkinsci/job-dsl-plugin/wiki/Job-reference#build-description-setter

To set the description of the seed job (the job with runs the Job DSL scripts), you can print something to the console log using println and then use the Description Setter Plugin to parse the log and set the description. Or you can use the Jenkins API from the DSL script:

def build = hudson.model.Executor.currentExecutor().currentExecutable
build.description = 'whatever'

Upvotes: 7

Related Questions