Hello,
I am trying to output the values in a bash file to Quickbuild variables after a step run. How would this be accomplished?
- solved #5
- replies 5
- views 830
- stars 1
-
Are you trying to create a bash file containing the QB variables? Or are you trying to parse the bash file and create variables in QB from that?
If it is the latter, my team uses a simple groovy step to read file and iterate over the contents, creating variables from each line (actually, we do it with a Windows CMD file, but the concept is the same). Something like:
fileName = sprintf( "%s/has_variables.sh", configuration.getWorkspaceDir());
new File( fileName ).eachLine { definition ->
(varName, varValue) = definition.split( "=" );
request.variables[ varName ] = varValue;
}
I got the "request.variables" syntax from elsewhere on this forum. It is important that the variables referenced in the file not already exist, or it will update the configuration with every build, which creates unnecessary audit entries.
The file creates a complex date that is then output and I am trying to import that value back into QB as a variable to be used by another step. Since I am unsure if we will need to create more of these, I am planning output all script results as new lines to the same file then try import everything at once into QB.
Hope that makes sense.
The command output can actually generate groovy scripts to be executed in QB. For instance, below commands take value of a shell variable and set as value of a QB variable:
SOME_SHELL_VAR="some value"
echo $SOME_SHELL_VAR
echo "## Begin QuickBuild Script"
echo "groovy:"
echo "vars.get(\"someVar\").setValue(\"$SOME_SHELL_VAR\")"
echo "## End QuickBuild Script"