skip to Main Content

I am currently working on dockerizing Jenkins FROM jenkins/jenkins:lts image. I am not so familiar with Groovy nor Jenkins, but I managed to run few scripts by adding this line to my 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. Is there a way to configure those using a Groovy script? If it’s not possible then is there any other way to do so?

2

Answers


  1. Chosen as BEST ANSWER

    Update (Jenkins configuration as code)

    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.

    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:

    unclassified:
      mailer:
        authentication:
          password: "AES-128-Encrypted password"
          username: "[email protected]"
        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:

    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)

    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):

    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)

    /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


  2. I’d recommend using Jenkins Configuration as Code -JCasC for as much of the Global Settings and plugin settings that are supported. A very %ge can be be done that way, including anyone. 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.

    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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search