0

I am Calling Groovy file In Build Command of the buildspec.yml and Would Like to Initialize An Variable in the Groovy script with An Environment Variable defined in Buildspec. How to get the Argument and initialize Variable with the Argument inside groovy. Below is my groovy script and Command.

groovysh check.groovy $fileNameList

import hudson.model.*


def nameList=fileNameList.tokenize(',')
def finalNameList=[]
for (i=0 ; i< nameList.size();i++)
{
println(nameList[i])
def sonarname="**/*"+nameList[i]+".html"
println(sonarname)
finalNameList.add(sonarname)
}
println(finalNameList)
String result = finalNameList.join(",")
def map = [sonarNameList: result]
println(map)
println(Sonar_Analysis)
return map

Need Initialize Variable fileNameList with Environment Variable $fileNameList defined in Buildspec.yml How to Implement this

1 Answers1

0

Define an environment variable in your buildspec and pass it to your function. You can then set your environment variables in CodeBuild console.

  env:
    variables:
       fileNameList: "abc, def"

  build:
    commands:
      - groovysh check.groovy ${fileNameList}
Vikyol
  • 5,051
  • 23
  • 24
  • Thanks for the reponse , I Tried the Above method and got the below exception. – Ashwini Natikar Aug 28 '19 at 06:55
  • [Container] 2019/08/28 06:53:26 Running command groovysh Check.groovy ${fileNameList} Aug 28, 2019 6:53:27 AM java.util.prefs.FileSystemPreferences$1 run INFO: Created user preferences directory. FATAL: groovy.lang.MissingPropertyException: No such property: US_BHCP_OPD_NPPINDICATIONS_201906_01 for class: groovysh_evaluate groovy.lang.MissingPropertyException: No such property: US_BHCP_OPD_NPPINDICATIONS_201906_01 for class: groovysh_evaluate – Ashwini Natikar Aug 28 '19 at 06:57
  • sorry, I can't help with that. I've never used groovy. – Vikyol Aug 28 '19 at 08:17