I have defined few variables as secret in the pipeline variables but when I try to use those by overriding the parameters file values with:
-secretsObject {"secrets":[{"secretName":"userpwd","secretValue":$(userpwd)}]}
I get "The provided value for the template parameter 'secretsObject' at line '1' and column '787' is not valid.'"
How should I pass the variables into the secrectObjects array?
It looks like the problem lies within the use of double quotes. I got it working with following example:
$(appId) ="a12b34cd-ab12-1ab2-ab1c-a12bc-34de56" -> no double quotes
$(password) = bestpassword -> use double quotes
Example override:
{"secrets":[{"secretName":"AppID","secretValue":$(appId)},{"secretName":"password","secretValue":"$(password)"}]}
Related
I am trying to replace single quote in a string with double quote using replace function with data factory expressions.
For example, replace single quote in the following string
hello'world ---> hello''world
#replace(pipeline().parameters.tst,''','''')
The above code is not working. Need help in fixing the code
You can declare a new parameter with the value ' (single quote). You can look at the following demonstration for reference.
I have taken 2 parameters, text with the value hello'world and replace_char with the value '.
I used a set variable activity to store the output of the replace() function (for demonstration) into variable named output (String). Now, I modified the value as:
#replace(pipeline().parameters.text,pipeline().parameters.replace_char,'"')
This successfully helps in replacing a single quote with double quote character.
NOTE: The \ in the output variable value indicates that the " is to be considered as a character inside the string value.
Use two single quotes to escape a ' character in string functions.
For example, expression #concat('Baba', '''s ', 'book store') will return below result.
Baba's book store
https://learn.microsoft.com/en-us/azure/data-factory/control-flow-expression-language-functions#escaping-single-quote-character
I have a pipeline parameter called myArray:
with following structure:
[
{
“Mapping“: “{ “sourceCol“: “ColA“ }“
“AnotherProperty“: 1
}
]
How can I escape the double quotes around sourceCol and ColA. As it seems that ADF is adding automatically a / to them.
In Azure data factory, backslash / appears wherever double quotes are used.
To avoid it, you can use replace() function to replace double quotes from the string or convert it to JSON.
You can check similar links 1 & 2 for reference.
I want to update a string in quotes in yaml file in Jenkins Job. While updating the file, single quotes around the string are replaced by triple quotes. Following is the method that I have written:
{
def fileName = 'config.yml'
datas = readYaml file: fileName
var = "'" + params.ReleaseBranchName + "'"
println var // this shows output as expected, string in single quotes -> 'rel-21.9'
datas.branchName = var
println datas // this prints the yaml with single quotes -> productiveBranch='rel-21.9',
writeYaml file: fileName, data: datas, overwrite: true //this show value in triple quotes -> productiveBranch: '''rel-21.9'''
}
Could someone suggest how can I save string with single quotes in yaml file? Thanks!
The value of var, as written, is 'rel-21.9', i.e. the single quotes are part of the value.
In YAML input, when 'rel-21.9' is encountered, the single quotes are not part of the value; they are part of the syntax and enclose the value, so the value is rel-21.9.
Therefore, if you want your value to be rel-21.9, which is most probably what you want, do not put single quotes in the value; just do var = params.ReleaseBranchName.
Your code does not do anything with var; I assume what you're trying is to put it into datas. This would result in YAML writing out "'rel-21.9'" (not triple single quotes, that can't happen since it would be invalid YAML). By surrounding the value with double quotes, the single quotes become part of the value just like your code requested.
When you do not put single quotes into the data, YAML will probably serialise it without any quotes. This is expected since rel-21.9 does not contain any special characters that would require quoting. There are ways to force a YAML processor to quote a value, but they are complex and I am unsure whether the API is exposed to Groovy. For references, this is how you would do it in Java.
Since you are editing a YAML file, you might want to read this question which details how and why updating YAML files in code can lead to style changes.
I'm trying to use a string variable as input to an xml function. When I use this command:
name2_node(i).setTextContent('truck');
there is no error. But when I replace it with:
name2_node(i).setTextContent(type(i,1));
an error occurs like this:
No method 'setTextContent' with matching signature found for class
'org.apache.xerces.dom.ElementImpl'.
The variable type is a string array. In fact when I type type(i,1) in command window the result is:
ans =
string
"truck"
What part am I doing wrong?
Two things:
use a different variable name, type is a built in function which tells you the variable type, hence why it shows "string" in the output.
Then access the cell array of strings with curly braces
vehicletypes = {'car'; 'truck'; 'van'};
name2_node(i).setTextContent(vehicletypes{i,1}); % For i=2, this passes 'truck'
I am generating strings with the names of existing variables. I want to use the strings to create a variable set to the VALUE of the existing variable, but I can't figure out how to achieve this.
Put another way if this helps:
A calling routine sends strings "abc" "cde" etc... Each string is the first several characters of a path variable I've already set. I then append "path" to the passed string to create the full name of the existing variable (e.g., %abcpath%) Now I want to get the value of %abcpath% and put it into a variable I can use it in the current routine.
Thanks for any help.
Here is part of the code I have:
SET abcPath=c:\path_to_abc_dir
SET cdePath=c:\path_to_cde_dir
call :names abc cde ...
:names
For %%G in (%*) do (
set name=%%G
:: Append "path" to name from calling routine
set namepath=!name!path
echo "!namepath!"
:: 1st time through namepath is "abcPath"
:: How to now set a var to the VALUE of %abcPath% set above?
::these don't work:
set dirpath=%%namepath%%
set dirpath=!%%namepath%%!
set dirpath=!%namepath%%%amepath%%!
set dirpath=!!name!path:%dirpath%=%%dirpath%%!
::I want to do things with %dirpath% in this routine:
if not "!dirpath!"=="" (
cd !dirpath!
:: call subroutine to get the number of files in the directory
call :forhere
do other stuff with var dirpath ...
)
)
....
::these don't work:
set dirpath=%%namepath%%
^^........^^ Not a valid variable reference
set dirpath=!%%namepath%%!
^^........^^ Not a valid variable reference
set dirpath=!%namepath%%%amepath%%!
^........^ This has been parsed at start and has no value
set dirpath=!!name!path:%dirpath%=%%dirpath%%!
^^ ^..........................^ two "variables" start and end
Delayed expasion over a value obtained with delayed expansion does not have a obvious syntax, because this does not exist. It can not directly be done and other commands need to be used
....
set "name=%%G"
set "namepath=%%Gpath"
call set "dirpath=%%!namepath!%%"
echo !dirpath!
....
Why or how does it work?
When the line is parsed, the only variable referenced is namepath with delayed expansion. The double percent signs are a escaped percent sign. So the line is translated into
call set "dirpath=%abcpath%"
Now, the call is executed, generating a second parse of the line, obtaining the correct value
This can also be done as
for %%a in ("!namepath!") do set "dirpath=!%%~a!"
In this case, the value inside namepath variable is stored into the for replaceable parameter and used to obtain the value to assign to the dirpath variable
In both cases, two "parse" (in the logic sense) operations are done.
In the first solution the first parse extracts the value of namepath and the second parse (invoked by call command execution) uses this value as a variable name.
In the second solution, we first get the value inside namepath (first "parse") and then this value is used in a new delayed expansion operation to retrieve the value to assign to dirpath