简体   繁体   English

从命令行运行groovy脚本时,Jenkins没有此类属性

[英]No such property for Jenkins while running groovy script from command line

Using script console I'm able to execute the below script without any issues. 使用脚本控制台,我可以执行以下脚本,而不会出现任何问题。 However whenever I run the script from command line I got the below error. 但是,每当我从命令行运行脚本时,都会出现以下错误。 Added a " Execute Groovy script " to the job throwing the same error. 向引发相同错误的作业添加了“ Execute Groovy脚本 ”。 " Execute system Groovy script " works fine. 执行系统Groovy脚本 ”可以正常工作。 Is there anything wrong I'm doing? 我做错什么了吗? Can somebody help me plz 有人可以帮我吗

import  jenkins.model.Jenkins.*;
jenkins = jenkins.model.Jenkins.instance

def item = jenkins.getItem("3rd-libraries")
def build = item.getLastBuild()

println build.isInProgress()

Caught: groovy.lang.MissingPropertyException: No such property: jenkins for class: job
groovy.lang.MissingPropertyException: No such property: jenkins for class: job
        at job.run(job.groovy:2)

Jenkins:2.18 詹金斯:2.18

Groovy: Groovy Version: 2.4.6 JVM: 1.7.0_40 Vendor: Oracle Corporation OS: Linux Groovy:Groovy版本:2.4.6 JVM:1.7.0_40供应商:Oracle Corporation操作系统:Linux

I think you're missing the def declaration for jenkins. 我认为您缺少詹金斯的def声明。

The second line should read; 第二行应为:

def jenkins = jenkins.model.Jenkins.instance

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM