我有点困惑,为什么在Jenkins Scriptler和脚本控制台中运行以下脚本时,它可以工作,但在**动态选择参数(Scriptler)**中使用时,它会失败,并显示以下错误:
Error: groovy.lang.MissingPropertyException: No such property: com for class: Script1
我只能假设它与所使用的类com有关。cloudbees. plugins. credentialsProvider被调用。
下面是脚本:
/*** BEGIN META {
"name" : "GetRemoteNasFolderList",
"comment" : "Retrieve a list of folder names (in reverse order) from a remote NAS location.",
"parameters" : [ 'ENVIRONMENT', 'SHARE_PATH', 'FOLDER_PATH' ],
"core": "1.565",
"authors" : [{
name : "Authors Name"
}]
} END META**/
import jenkins.model.Jenkins
try {
// params
def env = ENVIRONMENT // 'DEV" or 'TEST' or 'PROD'
def share_path = SHARE_PATH
def folder_path = FOLDER_PATH
String user_domain = ''
String nas_path = ''
switch (env) {
case 'DEV':
user_domain = 'dev';
nas_path = 'nas_host.dev.company.com.au';
break;
case 'TEST':
user_domain = 'test';
nas_path = 'nas_host.test.company.com.au';
break;
case 'PROD':
default:
user_domain = 'prod';
nas_path = 'nas_host.prod.company.com.au';
}
String user_name = 'myUserName'
def full_name = user_domain + '\\' + user_name
String pass_word = ''
def found = false
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class,
Jenkins.instance,
null,
null
);
for (c in creds) {
if (c.username == full_name) {
pass_word = c.password
found = true
}
}
if (found == true) {
url = "smb://" + nas_path + "/" + share_path + "/" + folder_path;
println("Url: "+url)
// println(user_domain+"\\"+user_name+", "+pass_word)
auth = new jcifs.smb.NtlmPasswordAuthentication(user_domain, user_name, pass_word);
dir = new jcifs.smb.SmbFile(url, auth);
folders = []
for (jcifs.smb.SmbFile f : dir.listFiles())
{
folders.push(f.getName().replace('/',''))
}
return folders.sort().reverse()
} else {
print("Credential entry not found for ( " + full_name + " )")
}
} catch (e) {
return ["Error: "+e]
} finally {
}
任何想法,任何人。
2条答案
按热度按时间wixjitnu1#
发生错误:groovy.lang。无此类属性:xx用于分类:年
如果缺少
import
引用,则会显示典型错误消息,您是否尝试过引用所有内容?这可能是Jenkins Scriptler和脚本控制台默认执行的操作,而动态选择参数(Scriptler)则不是。
参考:https://github.com/chef-cookbooks/jenkins/issues/174
bybem2ql2#
切换到使用一个不同的插件(活动选择参数),使脚本的使用,现在是工作。