change jenkins workspace and attach file with email using jenkins email-ext plugin

百般思念 提交于 2019-12-22 10:48:12

问题


I am new to jenkins and i want to add my test report with the email attachment.

I am using

Email-ext

plugin to send email. Email is sent successfully but the attached file is not sent.

My test report generates in eclipse porject workspace inside and path is

E:\eclipse_environment\workspace\smautomation_jenkin\assets\chromeTestReport\

how i can attache my test file with email using this plug-in?


回答1:


I am using mac and my solution works for mac.But i think the concept will be same for all os.

Actually, jenkin attach file from its workspace automatically. For this no expression is not required. For example, in my mac, jenkins workspace is

/users/dev/.jenkins/workspace

and i keep a file here named

 report.txt. 

And in "attachment" of email-ext plugin, just write

report.txt

no need to write any other thing. jenkins will go to its workspace and check "report.txt" exist or not. if exist, it send it as attachement.

Now question about the jenkins workspace.

Actually jenkins has its own workspace. You may need another workspace. To check jenkins workspace, go like this:

jenkins > manage jenkins > configure system.

Now at top u will see

Home directory

and theres an

Advanced 

option. Click on it and u will see

Workspace Root Directory: and its value is   
${ITEM_ROOTDIR}/workspace

ITEM_ROOTDIR is where .jenkins exist. For me this is

/users/dev/.jenkins

Actually u can see this at the first line:

    Home directory  -- ur ITEM_ROOTDIR is shown in this line.

now go to ${ITEM_ROOTDIR}/ and u will see a folder name workspace.

Now if u keep any file in this workspace, jenkin will send this file as attachement. Obviously u have to mention it in email-ext plugin "attachment" section.

Now if u want to change ur workspace, change ur

Workspace Root Directory:  

like this ${ITEM_ROOTDIR}/jobs/test/workspace

it depends on you.Change according to ur wish.

the most important thing is, if u change ur workspce from

jenkins > manage jenkins > configure system > Advanced option under Home directory

this will be ur default workspace.

If u want to make a specific workspace for only

one project

than u have to follow another procedure.

Just create a maven job (project). Than enter into the project,

//click on configure, now click on "Advanced" option under "Build"
//For free style project, this is in "Advanced project option"

There, u will see

Use custom workspace

check this option, and give ur needed workspace. For me i give like this:

 /users/dev/workspace/test1/

and this is

the workspace only for this project.

Now u can send file from here as an attachement.

one most important thing is u must restart jenkins server

to set the new workspace to ur job.

Actually u can copy files into jenkins workspace from another directory using cp command in

Execute shell option.

Now just give the file name in attachement of email-ext plugin and jenkins will send this file as attachment with ur email.

cheers.........




回答2:


This method worked for me, to include html file in jenkins workspace to a mail body.

jenkins -> configuration -> Editable Email Notification

Content Type : HTML(text/html)

Default Content: ${FILE,path="build/reports/tests/test/index.html"}

Don't start file path with "/"



来源:https://stackoverflow.com/questions/34067682/change-jenkins-workspace-and-attach-file-with-email-using-jenkins-email-ext-plug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!