jeffsmith712 jeffsmith712 - 6 months ago 216
Groovy Question

Jenkins Pipeline emailext $class parameter for recipientProviders

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 &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</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
but is
some sort of special reserved word in groovy to indicate class type?

2) In the source code,
is a
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.

Answer Source

1) 2) is about the same things:

[$class: 'DevelopersRecipientProvider'] is a map literal with key '$class'(note it is a string literal) and value 'DevelopersRecipientProvider'. Nothing special.

About recipientProviders: [[$class: 'DevelopersRecipientProvider']],

[[$class: 'DevelopersRecipientProvider']]is a list of map, 'recipientProviders' is the key same as 'subject' or 'body'.

You may think the emailext is a method with signature: void emailext(Map<String, Object> map)

3) emailext is a method implemented in Java. You can find source code here and here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download