Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dynamic Jenkins[动态选择参数(Scriptler)]在查询凭据信息时失败_Dynamic_Jenkins_Parameters_Credentials_Choice - Fatal编程技术网

Dynamic Jenkins[动态选择参数(Scriptler)]在查询凭据信息时失败

Dynamic Jenkins[动态选择参数(Scriptler)]在查询凭据信息时失败,dynamic,jenkins,parameters,credentials,choice,Dynamic,Jenkins,Parameters,Credentials,Choice,我有点困惑,为什么在Jenkins Scriptler和脚本控制台中运行以下脚本时它会工作,但在动态选择参数(Scriptler)中使用时,它会失败并出现错误: Error: groovy.lang.MissingPropertyException: No such property: com for class: Script1 我只能假设这与调用的类com.cloudbees.plugins.credentials.CredentialsProvider有关 以下是脚本: /*** BEG

我有点困惑,为什么在Jenkins Scriptler脚本控制台中运行以下脚本时它会工作,但在动态选择参数(Scriptler)中使用时,它会失败并出现错误:

Error: groovy.lang.MissingPropertyException: No such property: com for class: Script1
我只能假设这与调用的类com.cloudbees.plugins.credentials.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 {
}
任何想法,任何人

错误:groovy.lang.MissingPropertyException:类:yy没有这样的属性:xx

典型错误消息如果您缺少
导入
引用,是否尝试引用所有内容

import jenkins.model.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*;
也许这就是Jenkins Scriptler和脚本控制台在默认情况下所做的,而动态选择参数(Scriptler)则不这样做


Ref:

切换到使用另一个插件(Active Choices参数),该插件使用Scriptler脚本,现在正在工作。

是的,我有。在这篇文章之前,为了理智起见。相同的错误消息。您刚刚尝试使用另一个插件(Active Choices参数),该插件使用Scriptler脚本并正在工作。我不知道为什么我以前没有尝试过这个,但现在它让我感到困惑,动态参数没有,根本原因是什么。我可能应该继续前进,使用那些有效的东西,但这就是插件中的一个bug。