How to place Email-Ext groovy script on the jenkins file system

浪子不回头ぞ 提交于 2019-12-21 20:24:22

问题


I need to dynamically modify the notification e-mail recipients based on the build, so I'm using a groovy script. I want this script to be available to all jobs, so I want it to reside on the Jenkins file system and not within each project. It can be either in the recipients fields (using ${SCRIPT,...}) or in the pre-send script. A short (fixed) script that evaluates the master script is also good, as long it is the same for all projects.


回答1:


You should try Config File Provider plugin. It works together with the Credentials configuration of Jenkins.

  • Go to Manage Jenkins > Managed files
  • Click Add a new Config
  • Select Groovy file
  • Enter the contents of your script

Your script will now be saved centrally on Jenkins, available to master/slave nodes.

In your Job Configuration:

  • Under Build Environment
  • Check Provide Configuration file
  • Select your configured groovy File from dropdown
  • Set Variable with a name, for example: myscript

Now, anywhere in your job, you can say ${myscript} and it will refer to absolute location of the file on filesystem (it will be somewhere in Jenkins dir).




回答2:


My impression it that you would probably want to completely switch to Jenkins pipelines where the entire job is groovy file (Jenkinsfile) in the root of the repository.

Email-Ext already supports it even if it may be lacking some documentation. https://jenkins.io/doc/pipeline/steps/email-ext/



来源:https://stackoverflow.com/questions/25760914/how-to-place-email-ext-groovy-script-on-the-jenkins-file-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!