【问题标题】:Using Jenkins script console and seeing the Groovy output使用 Jenkins 脚本控制台并查看 Groovy 输出
【发布时间】:2015-05-26 02:14:18
【问题描述】:

当我在脚本控制台中运行简单语句时,我可以看到打印的输出,例如

println "hello"

但是,使用此代码,我在 Jenkins 脚本控制台中运行时看不到任何输出。你知道为什么吗 ?从计算机命令行运行时,代码打印得很好。

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"
    }
}

【问题讨论】:

    标签: java groovy jenkins


    【解决方案1】:

    AFAIK 您在 Jenkins 控制台中编写的脚本实际上是包装类的主要功能。一个带来所有预先导入的 Jenkins 类。这就是为什么您定义的 main 没有像您从计算机命令行执行脚本时那样编译到 Groovy run 方法中。

    如果您希望执行 main ,只需将其放在类定义之外,如下所示:

    class Product {
    ...
    }
    
     def p1 = new Product("Mobile", "10000", "Nokia")
     println(p1.toString())
     println "Hello"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-30
      • 2018-05-13
      • 2020-05-24
      • 2020-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多