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.

in a build (batch/shell) step, trying to execute cmd through ${groovy: return cmd} failed #3837

HealingQuickly ·

Hello Robin

In one of my step, which is a build of shell/batch command type, I am trying to execute the command through groovy, because the command line is stored in a var (in the 2nd line to be specific). So in the command window, my whole script is this:

${groovy:
def value = vars.getValue("var_with_cmd");
def cmd = "";
value.eachLine {line, count -> if (count == 1) cmd = line; };
return cmd;
}

however, it keeps giving me the syntax error as follows:

script1507660946877568731772.groovy: 4: expecting '}', found '' @ line 4, column 59.
-> if (count == 1) cmd = line;
^

1 error

I can't figure out what happened. I just know it's about the usage of embedding groovy script.
Thank you for your help

  • solved #2
  • replies 1
  • views 1313
  • stars 0
robinshen ADMIN ·

For embedded groovy script, you will need to escape }, like below:

${groovy:
def value = vars.getValue("var_with_cmd");
def cmd = "";
value.eachLine {line, count -> if (count == 1) cmd = line; \};
return cmd;
}