Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

how to reference variable in setValue method #4400

veljkoc ·

I am using very short snippet of groovy code in my build step (bash script) to retrieve and set variable. I have a variable defined in configuration which value I can easily retrieve using the short groovy code.

${vars.getValue("var_name")}

If I want to set static string as a new value for this variable I can do it like this:

${vars.get("var_name").setValue("NEW VALUE")}

This static string works OK!!!
But if I want to use in setValue method some other variable which is previously defined in this Step with bash script:

file_name="NEW VALUE"
${vars.get("var_name").setValue($file_name)}

I am getting an error:

ERROR - Step 'master>lin_download_artifactory' is failed: Failed to evaluate below expression in configuration 'root/arena':
mvel:vars.get("var_name").setValue($file_name)

I tried as well:

${vars.get("var_name").setValue(file_name)}

The same** ERROR!**

Can you please tell me how I could reference variable within the setValue method? I tried also setValue(file_name) but it doesn't work as well.

  • solved #2
  • replies 7
  • views 337
  • stars 0
robinshen ADMIN ·

All groovy code inside ${...} will be executed before executing bash. So you can not pass bash variable to groovy code.

veljkoc ·

Thank you Robin for your kind reply.
Does groovy code always have to be executed before the all the other bash commands and statements? Can this somehow be changed or this is embedded QuickBuild logic?

Thanks

robinshen ADMIN ·

Unfortunately all groovy code has to be executed and all ${...} will be replaced with execution result before submitting the script to shell, as groovy script is unknown to shell.

veljkoc ·

Thank you Robin once again!

Is it possible using the Bash script to set value of the configuration variable or this is possible only through the groovy?

Thanks

robinshen ADMIN ·

It is not possible to set variable value via bash script. This can only be done via groovy.

nini10 ·
robinshen ADMIN ·

Thanks for the remind. This way the script can be executed while QuickBuild parsing the command output. I forgot this feature ever exist in QB!