0

I want jenkin to send an email for example 3 hours earlier, before a job runs. Email Notification or Editable Email Notification give no option of scheduling the Email Notifications. The purpose of such kind of notification is that the other departments in our company knows in advance that some specific job is gonna run and they do necessary steps before a job can run. Any idea or clue will be appreciated.

Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67
Ghulam
  • 91
  • 12
  • Adding the `jenkins-pipeline` tag is misleading and is why you are getting an answer related to a Jenkins Pipeline job instead of the type that you want. – Matthew Schuchard Mar 04 '19 at 14:32
  • Yea, you are right Matt. I found that out later too. The answer from vnscorner seems relevant now. – Ghulam Mar 18 '19 at 11:55

2 Answers2

1

Add a pre-build step and add "Execute shell" option. Add unix script for sending email with appropriate content. Add sleep command for 3 hours to hold the build for next 3 hours.

mailx -S smtp=$smtphost:$smtpport -s "subject line" -v foo@baa.com sleep 3600

VN'sCorner
  • 1,532
  • 1
  • 9
  • 13
0

You may add a 'pre-build' stage to your pipeline, which send a notification email about upcoming job run. You can also set a 'sleep' operation afterwards to give your colleagues some time to prepare:

pipeline {
    stages {
      stage('Pre-Build Email'){
       emailext(
          body: 'Job XYZ is about to run in 30 minutes.',
          from: env.DEFAULT_REPLYTO,
          replyTo: env.DEFAULT_REPLYTO,
          subject: 'Job XYZ notification',
          to: mailinglist@company.com'
       )
      sleep(time:30,unit:"MINUTES")
    } 

    // Rest of the build here
AutomatedOwl
  • 1,039
  • 1
  • 8
  • 14
  • But I don't have any pipeline jobs. I have freestyle jobs, which runs at the scheduled time. – Ghulam Mar 04 '19 at 12:22
  • so you can just put the relevant build steps in the UI section, same thing – AutomatedOwl Mar 04 '19 at 13:32
  • UI section? I'm not sure, if I'm following you. I have General, Source Code Management, Build Triggers, Build Enviroment, Build and Post Build Sections under Freestyle Project. – Ghulam Mar 04 '19 at 13:49
  • just add two 'Build' steps one after another. The first one of email notification and the second one is a delay (you may use 'execute shell' for 10 minutes delay for example - sleep 3600) – AutomatedOwl Mar 04 '19 at 13:55
  • I understand you are trying to say, but the email notification is only in post build step. So if put the delay in Build Step, it will for example wait 10 minutes and after 10 minutes, it will send the email. – Ghulam Mar 04 '19 at 14:06
  • What I want, is the complete opposite, so it first sends the email, then wait for example for 10 minutes and then starts the other job. – Ghulam Mar 04 '19 at 14:07
  • Use this groovy plugin https://wiki.jenkins.io/display/JENKINS/Groovy+plugin and add a build of executing a groovy script which sends an email like I did in my answer to you. – AutomatedOwl Mar 04 '19 at 15:05