If you set the variable in Variables tab but don’t specify its value, its value is null.
However, when referring to this variable in scripts, it will be parsed to null string and is not null value.
For example, we have a test.json with below content.
"setting": "debug",
"environment": "dev"
}
If we use the command line task with below content.
echo Hello world
cat $(System.DefaultWorkingDirectory)/_tt/test.json
echo ""
echo "now replace: "
sed "s/"debug"/$testvar/g" $(System.DefaultWorkingDirectory)/_tt/test.json
The output result is below.
If you want to set it to null, just directly use null value with below content.
sed 's/"debug"/null/g' $(System.DefaultWorkingDirectory)/_tt/test.json
The output result is below.
And usesed 's/"debug"/null/g' $(System.DefaultWorkingDirectory)/_tt/test.json >$(System.DefaultWorkingDirectory)/_tt/new_test.json
will write output to new_test.json file.
See: How to Use sed to Find and Replace String in Files for details.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…