I have YAML file which needs to take a variable as an input:
outputters:
- type : DateFileOutputter
name : logfile
level : DEBUG
date_pattern: '%Y%m%d'
trunc : 'false'
dirname : "/home/sameera/workspace/project/log"
filename : "message.log"
formatter :
date_pattern: '%m/%d/%Y %H:%M:%S'
pattern : '%d %l - %m'
type : PatternFormatter
I want to pass dirname
as a parameter, something like:
dirname : "<%= LOGFILE_PATH%>"
My LOGFILE_PATH
is defined in a file called init.rb
.
In YAML, you can only define variables with pipeline or action scope. Workspace and project variables need to be defined via the GUI.
Passing variables between tasks in the same job For example, to pass the variable FOO between scripts: Set the value with the command echo "##vso[task. setvariable variable=FOO]some value" In subsequent tasks, you can use the $(FOO) syntax to have Azure Pipelines replace the variable with some value.
YAML has three types of data types: Scalar. List. Dictionary.
You could use ERB.
For example:
template = ERB.new File.new("path/to/config.yml.erb").read
processed = YAML.load template.result(binding)
You can read more on binding here: ruby metaprogramming.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With