2016-05-16 375 views
1

这个程序的目的是取代所有TFS用户的密码。如果我直接在代码中使用用户标识和密码,但它在我将其转换为参数化构建时失败并出现此错误。Jenkins groovy.lang.MissingPropertyException:没有这样的属性:对于类:Script1

Started by user Jirong Hu 
[EnvInject] - Loading node environment variables. 
Building remotely on public_jenprodslave_1 in workspace D:\public_jenprodslave_1\workspace\DevOps\Update-TFSPlugin-Password 
param userid value : devops_test_user 
ERROR: Build step failed with exception 
groovy.lang.MissingPropertyException: No such property: userid_param_value for class: Script1 


import hudson.model.* 
import hudson.triggers.* 
import hudson.util.Secret; 
import hudson.plugins.tfs.TeamFoundationServerScm 

def thr = Thread.currentThread() 
def build = thr?.executable 
def resolver = build.buildVariableResolver 

def userid_param = "userid" 
def userid_param_value = resolver.resolve(userid_param) 
println "param ${userid_param} value : ${userid_param_value}" 

def password_param = "password" 
def password_param_value = resolver.resolve(password_param) 
//println "param ${password_param} value : ${password_param_value}" 


updateTFSPluginPassword(Hudson.instance.items) 

def updateTFSPluginPassword(items) {  

    for(item in items) { 
     if (item.class.canonicalName != 'com.cloudbees.hudson.plugins.folder.Folder') { 

      if (item.scm instanceof TeamFoundationServerScm) {          

      // Update the TFS user id here: 
      //if (item.scm.getUserName() == 'devops_test_user') { 
      if (item.scm.getUserName() == userid_param_value) { 
       println("Working on project <$item.name>") 
       println item.scm.getType() 
       println item.scm.getServerUrl() 
       println item.scm.getProjectPath() 
       println item.scm.getWorkspaceName() 
       println item.scm.isUseUpdate() 
       println item.scm.getUserName() 
       println item.scm.getPassword() 

       // Update the TFS user password hash here:     
       Secret secret = Secret.fromString(password_param_value) 

       tfsSCM = new TeamFoundationServerScm(item.scm.getServerUrl(), 
                item.scm.getProjectPath(), 
                null, 
                item.scm.isUseUpdate(), 
                item.scm.getWorkspaceName(), 
                item.scm.getUserName(), 
                secret) 
       item.scm = tfsSCM 

       println ("") 

      }    
      } 

     } else {    
      updateTFSPluginPassword(((com.cloudbees.hudson.plugins.folder.Folder) item).getItems()) 
     }  
    } 
} 

回答

1

我想你可能需要在所提及的属性上使用Field注释。请再看看here

+0

它将Field注释添加到所有变量后工作。谢谢你的帮助! –

1

原因之一groovy.lang.MissingPropertyException:当您尝试访问超出其作用域的变量或您尚未定义该变量时,会引发此错误。

相关问题