Reputation: 24778
When I run simple statements in the script console I can see the output printed, e.g.
println "hello"
However with this code I see no output printed when run in Jenkins script console. Do you know why ? The code prints just fine when run from computer command line.
class Product{
private String name
private def price
def vendor
public Product(){
}
Product(name, price, String vendor){
println "Constructor";
this.name = name
this.price = price
this.vendor = vendor
}
public String getName(){
return name
}
def setName(name){
this.name = name
}
public String getPrice(){
return price
}
def setPrice(price = 100.00){
this.price = price
}
def String toString(){
return "Name = $name, Price = $price, Vendor = $vendor";
}
static main(arguments){
def p1 = new Product("Mobile", "10000", "Nokia")
println(p1.toString())
println "Hello"
}
}
Upvotes: 2
Views: 1392
Reputation: 2879
AFAIK the script you're writing in the Jenkins console is actually the main function of a wrapper class. The one that brings all the pre-imported Jenkins classes. That's why the main
you're defining isn't compiled into Groovy run
method as it is done when you're executing the script from computer command line.
If you want your main to be executed just put it outside of the class definition like this:
class Product {
...
}
def p1 = new Product("Mobile", "10000", "Nokia")
println(p1.toString())
println "Hello"
Upvotes: 3