Search code examples
jenkinspublic-key-encryptiongnupgjenkins-plugins

How to configure Jenkins to send encrypted emails with gpg?


I am looking for instructions on how to configure the jenkins email plugin (ext-mail) to encrypt notifications? The uncle google did not help me too much.


Solution

  • such feature is not out-of-box, you need custom ExtendedEmailPublisher for your needs.

            MimeMessage msg = createMail(mailType, build, listener);
            Address[] allRecipients = msg.getAllRecipients();
            if (allRecipients != null) {
                StringBuilder buf = new StringBuilder("Sending email to:");
                for (Address a : allRecipients) {
                    buf.append(' ').append(a);
                }
                listener.getLogger().println(buf);
                Transport.send(msg);
                if (build.getAction(MailMessageIdAction.class) == null) {
                    build.addAction(new MailMessageIdAction(msg.getMessageID()));
                }
                return true;
            }
    

    you can get Recipients and Email message for sign/encrypt and call Transport.send(msg) at last.