Reputation: 735
I have a list of email ids in a Jenkins environment variable(emailsdl) and trying to use this for recipients:
in Jenkins Pipeline Mailer as below:
mail (to: 'Mailer', recipients: '${env.emailsdl}',
subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) is waiting for input",
body: "Please go to ${env.BUILD_URL}.")
With the above code I am not receiving email and receiving an error:
Email not sent. No recipients of any kind specified ('to', 'cc', 'bcc').
But when I replace ${env.emailsdl}
with real email([email protected]) then it does trigger an email. I even tried env['emailsdl']
and it didn't work.
Is there a way I can pass environment variable for recipients in this case?
Upvotes: 0
Views: 3092
Reputation: 6976
In groovy if you use single quoted string it will not be interpolated, which means that in the string '${env.emailsdl}'
the variable env.emailsdl
will not be replaced. You need to use double quoted string: "${env.emailsdl}"
Upvotes: 2
Reputation: 735
@Gergely: Your suggestion helped me resolving my issue. The problem is that I have a local environment variable which was assigned with a value from other global environment variable: globalVar = [email protected]
and emailsdl=${globalVar}
is in job's local properties. Now I am calling this emailsdl
in pipeline script. This has been resolved by:
env.((env.emailsdl).replaceAll("\$", ""))
Upvotes: 1