I am trying to write a groovy files that parse some data and send email.
I tried to import below packages for this purpose:
import javax.mail.*
import javax.mail.internet.*
And tried to run the groovy file as ./test.groovy , but it shows the error "import command not found"
Is this the correct way to run the groovy script? Anyone please help me to write a groovy script that helps to email
The javax.mail classes are not part of the JDK, so you need to explicitly include them. In a Groovy script, the easiest way to do this is with #Grab, e.g.
#Grab(group='javax.mail', module='mail', version='1.4.7')
import javax.mail.*
import javax.mail.internet.*
// the rest of your script goes here
You can send an email by using the Email-ext plugin as follows:
emailext body: '''African child
African child''', subject: 'African child', to: 'patrick#xxxx'
Note that this will only work within a proper job, not in Jenkins script interface
Related
I am very new to coding and am trying to write a practice script for webscraping in VS Code Editor. But every time i run the script i get this issue of there being no real output. Can you please advise on what the issue is? Note: the pink boxes are just covering my nameenter image description here
I tried running the code and expected webscraped data from the link. I have tried many different scripts and the same issue happens. So there must be something wrong with the whole system i think
VSCode is an excellent IDE. When you start a new project (or open a folder in VSCode), it does not come with any build tools or compilers etc. You have to manually configure them. You have to set up the environment using different toolchains. Here are some instructions for Python
This is not a problem with VSCode but I am going to answer your question.
You can't webscrape indeed.com with requests and beatiful soup because it has bot protection using cloudflare. If you take a closer look to the response it returns the 403 Forbidden status code instead of 200 OK. You can scrape using a headless browser using selenium.
Here's an example
First install selenium and webdriver_manager
pip install selenium webdriver_manager
from selenium.webdriver import Chrome, ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
# Make sure you are not detected as HeadlessChrome, some sites will refuse access
options = ChromeOptions()
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = Chrome(options=options, service=Service(
ChromeDriverManager().install()))
# Make sure you are not detected as HeadlessChrome, some sites will refuse access
ua = driver.execute_script("return navigator.userAgent").replace(
"HeadlessChrome", "Chrome")
driver.execute_cdp_cmd("Network.setUserAgentOverride", {
"userAgent": ua})
driver.execute_script(
"Object.defineProperty(navigator,'webdriver',{get:()=>undefined});")
driver.get("https://www.indeed.com/companies/best-Agriculture-companies")
main = driver.find_element(By.ID, "main")
I am working on a CI system with Jenkins. But now I got a problem. I need to do the following steps.
1:Jenkins build
2:Deploy to Tomcat
3:find a way to send the build parameters (Job Name, build number...) to a web server (I am using REST now).
4:Web Server trigger testing system.
5:Jenkins get the result from testing system.
6:update build status
7:send emails.
I have problem with the step 3. I need to send those info after the deploy. I am thinking a way as following.
write those parameters to a file during build step, then call a script or Java problem to process the file and send out those info by REST.
But that is ugly. Is there any better ways to do it?
Side questions
Can groovy do this?
How to import groovy http-builder library to Jenkins?
I found a walk around solution.
1: ran echo command during the build to get the build ID and print to log.
2:wrote a small Java program to get the JSON response of the build then sent the necessary info as rest request to the server you set. The program is like a message forwarder.
3:in post build actions, use groovy post build to fetch the log then call the Java program.
I have a script 'localfunc.py' with different functions, and a main script 'doIt.py' with the following import code:
import localfunc
localfunc.aMethodToExecute()
I'm new to Python/Jython, but i think this is correct, right?
My problem is that when executed in Eclipse onto my local websphere server (right clic on script->Run as -> execute as administrative script) i get the following error message:
ImportError: no module named localfunc.
I'm using WAS 8.5.2 and Jython version is 2.1 for information.
Somebody has an idea why it's not working with Eclipse?
Quite easy finally to solve this problem. In your running configuration, update the setting in 'Arguments' > working directory by selecting 'other' and your main script directory.
For example if your working directory looks like:
src/scripts/
start.py
lib/
localfunc.py
Select 'src/scripts/'
It works now.
I need a command that helps me to find a solution for the following problem:
logging the failed cases of selenium ide and send them to an email using selenium ide commands.
Thanks.
Omar
Please refer following URL to execute Selenium-IDE HTML Scripts using Selenium RC. Using this you will get HTML result file. To get screenshot you can add captureScreenshot command after failed step.
http://www.softwaretestingdiary.com/2012/02/selenium-core-setup-to-execute-selenium.html
I've set up my jenkins to send emails after nunit tests are passed. How can I configure that the body of mail contains nunit results from TestResult.xml file? Maybe there is some plugin to jenkins?
I think you should take a look to the Email-ext plugin, it will allow you to decide what you want to send (and in your cae attach NUnit report).
I've found suitable solution for me: use Jelly script as described here:
https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin