I have been trying to get my head around the pipeline groovy code below:
emailext (
subject: "STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """<p>STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
recipientProviders: [[$class: 'DevelopersRecipientProvider']]
)
1) Does the dollar sign before the class (which is $class) have some special meaning? I know it refers to the class type DevelopersRecipientProvider but is $class some sort of special reserved word in groovy to indicate class type?
2) In the source code, recipientProviders is a List but what exactly is being assigned to it in the code above? Is it a list of maps?
3) Where is emailext defined in the email ext plugin source code? I searched for emailext in all the .groovy files in the plugin source code but can't seem to find something that looks like the emailext call above.
I would appreciate if someone could shed some light on the above, thanks.
To add, the $class literal is a special key used by the Jenkins Pipeline. When editing a pipeline job, set the script source to inline (not SCM) and there is a link to the syntax reference. In that section there is a sub-section "Steps Reference" which is at https://<jenkins url>/job/<job name>/pipeline-syntax/html.
As maps of parameters. Default values may be omitted. (Note that
[1, 2, 3]is a list in Groovy whereas[a: 1, b: 2, c: 3]is a map.)The special map key
$classis used to represent the simple or (where necessary) fully-qualified class name of the object being requested.$classmay be omitted where the containing parameter allows only a single kind of nested object (or list of them):
checkout([$class: 'GitSCM', userRemoteConfigs: [[url: 'git://…'], extensions: [[$class: 'CleanBeforeCheckout']]])In this example,
GitSCMmust be specified to distinguish the kind ofSCMused by thedelegateofcheckout(the single mandatory parameter name delegate can be omitted), andCleanBeforeCheckoutmust be specified to distinguish the kind ofGitSCMExtensionused by theextensionsofGitSCM— a “heterogeneous” list; but$class: 'UserRemoteConfig'may be omitted since theuserRemoteConfigsofGitSCMare defined to contain onlyUserRemoteConfigs — it is a “homogeneous” list. (No such omission is permitted for homogeneous lists in the first syntax.)Note that in cases where a single parameter is given, with the name omitted, and that parameter is a map, it must be enclosed in parentheses to avoid a syntactic ambiguity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With