How to host Email-Ext groovy script on jenkins filesystem
I need to dynamically modify email notification recipients based on assembly, so I am using a groovy script. I want this script to be available for all jobs, so I want it to be on the Jenkins filesystem, not inside every project. It can be either in recipient fields (using $ {SCRIPT, ...}) or in a pre-submission script. The short (fixed) script that the master script evaluates is also good as it is the same for all projects.
source to share
You should try Config File Provider . It works in conjunction with Jenkins' Credentials configuration .
- Go to Jenkins Management > Managed Files
- Click Add New Configuration
- Select Groovy file
- Enter script content
Your script will now be stored centrally on Jenkins, accessible to master / slave nodes.
In your job configuration:
- At the Build Environment
- Check Provide config file
- Select your customized groovy File from the dropdown menu
- Set a Variable with a name, for example:
myscript
Now, wherever you are, you can tell ${myscript}
and it will refer to the absolute location of the file on the filesystem (it will be somewhere in the Jenkins directory).
source to share
My impression is that you probably want to completely switch to Jenkins pipelines where the whole groovy file (Jenkinsfile) job is at the root of the repository.
Email-Ext already supports it, even if it lacks documentation. https://jenkins.io/doc/pipeline/steps/email-ext/
source to share