sorry for the gibberish in the text. I'm a bit tired and in a hurry ... e.g fugred instead of figured ;)
On 20 Mrz., 11:56, Jan Seidel <wakkal...@gmail.com> wrote: > Hi folks, thanks for you replies :) > > @shanz just fugred it out tonight, was just a bit late to let you > know. > > @Didier your approach won't work as the env variables you are pointing > to are somewhat static. You can't modiefy them from within a job at > build time. > This would require 3 stages. Manipulate the config.xml (?) of Jenkins > with regular expressions, reload the configuration and run the job or > do it manually. Not nice approach. I am using this in one test > scenario which will be implemented that way but I am not fancy about > it. > > I did find an option "Set environment variables through a file" - I > suppose this is from a plugin. That would work for me to as there is > an upstream job running which could create the file. But why handle > around with environments, regular expressions to escape special > characters if the script provided by Shanz also can stream the content > of the already existing and updated template? ;) > > I will implement it in all release build jobs > The script looks now like this and is for me a perfect solution :) > > import smtplib > import os > from email.MIMEMultipart import MIMEMultipart > from email.MIMEBase import MIMEBase > from email.MIMEText import MIMEText > from email.Utils import COMMASPACE, formatdate > from email import Encoders > > files=[] > to=["m...@elektrobit.com","some...@elektrobit.com"] > cc=["distribution_list"] > subject = "new XXXXXX integrations available" > text = open('delivery_mail_all.txt','r') > > # Send the email via our own SMTP server. > def send_mail(to, subject, text, fromWho="m...@elektrobit.com", > files=[], cc=[], bcc=[], server="192.0.0.1"): > assert type(to)==list > assert type(files)==list > assert type(cc)==list > assert type(bcc)==list > > message = MIMEMultipart() > message['From'] = fromWho > message['To'] = COMMASPACE.join(to) > message['Date'] = formatdate(localtime=True) > message['Subject'] = subject > message['Cc'] = COMMASPACE.join(cc) > > message.attach(MIMEText(text.read())) > > for f in files: > part = MIMEBase('application', 'octet-stream') > part.set_payload(open(f, 'rb').read()) > Encoders.encode_base64(part) > part.add_header('Content-Disposition', 'attachment; > filename="%s"' % os.path.basename(f)) > message.attach(part) > > addresses = [] > for x in to: > addresses.append(x) > for x in cc: > addresses.append(x) > for x in bcc: > addresses.append(x) > > smtp = smtplib.SMTP(server) > smtp.sendmail(fromWho, addresses, message.as_string()) > smtp.close() > > send_mail(to, subject, text, "EB Software Integration", files) > > Only thing I haven't figured out yet is if someone wants to reply. The > name displayed is EB Software Integration as I have hardcoded it in > the send_mail call so the fromWho variable isn't used. > But I would like that EB Software Integration is resolved to fromWho. > I have been researching some approaches which didn't work (probably > due to my lacking skills in python). > This is actually not really giving me head aches at the moment. The > necessary function is available and people can get in touch with me as > my signature is in that mail. This minor glitch can be solved at a > more convenient time :) > > Take care > Jan > > On 20 Mrz., 11:37, shanz <duncan.perr...@gmail.com> wrote: > > > > > > > > > Oh yes, you need to define subject up near the top of the script and > > change the final call to send_mail(). > > Eg: > > import smtplib > > import os > > from email.MIMEMultipart import MIMEMultipart > > from email.MIMEBase import MIMEBase > > from email.MIMEText import MIMEText > > from email.Utils import COMMASPACE, formatdate > > from email import Encoders > > > myRelease = os.environ.get("BUILD_STRING") > > files=["myData.xml","myDataNightly_Previous.xml","myDataRelease_Previous.xml", > > "myReport.html"] > > to=["an.ema...@address.com","an.ema...@address.com","an.ema...@address.com"] > > text1 = "To everyone\n\nmyData.xml has changed following the latest > > build :- " > > text2 = myRelease > > text3 = "\r\n\nSee attached files\r\n\r\nReleases are in\"\\\\netdrive > > \Product source code\Tagged\", \r\n\nNightly files are in \"\\\ > > \netdrive\Product source code\Nightly\"\r\n\nRegards,\r\n\nJenkins\r > > \n" > > text = text1+text2+text3 > > subject="myNewEmailSubject" > > > # Send the email via our own SMTP server. > > def send_mail(to, subject, text, fromWho="", files=[], cc=[], bcc=[], > > > etc etc > > > send_mail(to, subject, text, "jenkins", files)