在作业dsl中没有发生变量替换

时间:2017-02-21 11:55:22

标签: groovy jenkins-job-dsl

只要我的SVN仓库中有新的分支条目,就会尝试创建新的工作,这是脚本。

svnCommand = "svn list --xml http://myrepo/svn/repo_name/branches"
def proc = svnCommand.execute()
proc.waitFor()
def xmlOutput = proc.in.text
def lists = new XmlSlurper().parseText(xmlOutput)
def listOfBranches = lists.list.entry.name

listOfBranches.each(){
  def branchName = it.text()
println "found branch: '${branchName}'"
}

mavenJob('${branchName}'){
  mavenInstallation('M3.3.9')
  logRotator(365, 25, -1, -1)

   scm {
     svn {
       location('http://myrepo/svn/repo_name/branches/${branchName}') {
        credentials('4t4d8ef-p67a-5298-a011-580ghe898a65')
       }
     }
   } 
}

脚本能够通过分支进行迭代并打印分支名称,

找到分支:' feature_01'

但我正面临这个问题,而在创建作业名称和使用svn分支名称时进行变量替换。

  

hudson.model.Failure:'$'是一个不安全的角色

詹金斯 - V.2.32

Job DSL - V.1.57

请提出任何建议。谢谢。

1 个答案:

答案 0 :(得分:3)

@Rao是对的:首先 - 你必须改变:

mavenJob('${branchName}')

到:

mavenJob(branchName) 

location('http://myrepo/svn/repo_name/branches/${branchName}‌​')

为:

location("http://myrepo/svn/repo_name/branches/${branchName}‌​")

此外,迭代内的def branchName = it.text()仅将变量的范围限制为此迭代。尝试:

listOfBranches.each() {
  branchName = it.text()
  println "found branch: '${branchName}'"
}