简体   繁体   English

如何配置 Jenkins email 开机通知?

[英]How to configure Jenkins email notification on start up?

I am currently working on dockerizing Jenkins FROM jenkins/jenkins:lts image.我目前正在对 Jenkins FROM jenkins/jenkins:lts图像进行 dockerizing。 I am not so familiar with Groovy nor Jenkins, but I managed to run few scripts by adding this line to my Dockerfile我对 Groovy 和 Jenkins 不太熟悉,但我通过将此行添加到我的 Dockerfile 来设法运行一些脚本

COPY /jenkins/script.groovy /usr/share/jenkins/ref/init.groovy.d/

The problem is that I couldn't find a way to automatically setup the email notification settings such as SMTP server, check the checkbox of Use SMTP Authentication .问题是我找不到自动设置email 通知设置的方法,例如SMTP 服务器,选中 Use SMTP Authentication 复选框 Is there a way to configure those using a Groovy script?有没有办法使用 Groovy 脚本配置那些? If it's not possible then is there any other way to do so?如果不可能,那么还有其他方法吗?

Update (Jenkins configuration as code)更新(Jenkins 配置即代码)

I managed to set up the email config using JCasC plugin thanks to Ian W on the recent answer, it wasn't the answer for my question but helped me follow through.感谢Ian W在最近的回答中,我设法使用 JCasC 插件设置了 email 配置,这不是我的问题的答案,但帮助我完成了。

So to set up a config in this example you will need to set up just mailing config or even more, so all you need to do is create a new file with a YAML configuration like this:因此,要在此示例中设置配置,您只需要设置邮件配置或更多,因此您需要做的就是创建一个具有 YAML 配置的新文件,如下所示:

unclassified:
  mailer:
    authentication:
      password: "AES-128-Encrypted password"
      username: "example@gmail.com"
    charset: "UTF-8"
    smtpHost: "smtp.gmail.com"
    smtpPort: "465"
    useSsl: true
    useTls: false

type the email and other configs like SMTP settings in plain text but for the password, you will need an encrypted password (AES-128), to do so you can simply go to:纯文本形式输入email和其他配置,例如SMTP设置,但对于密码,您需要加密密码 (AES-128),为此您只需输入 go 即可:

http://<jenkins-ip>:<jenkins-port>/script

You will have a text box to type the following groovy script to encrypt that password (update your password to match your email's pass)您将有一个文本框来键入以下 groovy 脚本来加密该密码(更新您的密码以匹配您的电子邮件密码)

import hudson.util.Secret

def secret = Secret.fromString("Your Password")
println(secret.getEncryptedValue())

Once you run the script you will get a new encrypted password, simply copy then paste it in the Config file password field.运行脚本后,您将获得一个新的加密密码,只需将其复制然后粘贴到配置文件密码字段中即可。

Now we are going to simply use that file to apply the new mail configuration by visiting (again make sure that you have configuration-as-code plugin installed):现在我们将通过访问简单地使用该文件来应用新的邮件配置(再次确保您安装了configuration-as-code插件):

http://<jenkins-ip>:<jenkins-port>/configuration-as-code/

Then copy the configuration file path inside the config path field (you can also use a URL of a config)然后复制config path字段里面的配置文件路径(也可以用一个config的URL)

/path/to/conf.yaml

and finally, apply a new configuration!最后,应用一个新配置!

You can use the JCasC for your desire find more here also see the GitHub repo您可以根据需要使用 JCasC 在此处找到更多信息,另请参阅GitHub 存储库

I'd recommend using Jenkins Configuration as Code -JCasC for as much of the Global Settings and plugin settings that are supported.我建议使用Jenkins 配置作为代码 -JCasC来支持尽可能多的全局设置和插件设置。 A very %ge can be be done that way, including anyone.一个非常 %ge 可以这样做,包括任何人。 Easiest approach is manually configure an Instance (local is fine), export settings via JCasC, backup actual configure, wipe configure, load JCasC and compare to backup.最简单的方法是手动配置实例(本地很好),通过 JCasC 导出设置,备份实际配置,擦除配置,加载 JCasC 并与备份进行比较。

eg: mailer plugin例如: 邮件插件

It does not handle the installation of the plugins ,so you must do that first, maybe via plugin manager installation tool or Docker file它不处理插件的安装,所以你必须先这样做,可能通过 插件管理器安装工具Docker 文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM