Reputation: 1231
In an ordinary Azure pipeline (no release), based on the input parameter I want to tedit a XML file used in the pipeline. For example I want to change log level if needed. Next, the file would be loaded by az storage file upload
- task: myTask@1
displayName: 'Upload Config File'
inputs:
scriptLocation: 'inlineScript'
inlineScript: |
myConfiguration="${{ parameters.name }}-configuration.xml"
# here want to modify the xml above
az storage file upload --share-name $(config-file-share) \
--source "$(input-files-path)/${myConfiguration}"
After reading Azure File transforms and variable substitution reference I'm a little bit lost... can I use is it mechanism in no release pipeline? But if I can, I have no idea how to apply this... It's hard to about a good example. I think that an easier way would be just use awk.
Could you please share your opinion and an example if have?
Upvotes: 1
Views: 194
Reputation: 35194
Can I use is it mechanism in no release pipeline?
Of course. You can do it in an ordinary Azure pipeline.
But when replacing the value of the xml file, you need to use variable, so you need to convert the value of parameters to the value of variable.
You could use the Replace Tokens task
from the Replace token extension.
Here is an example:
XML file:
Yaml sample:
parameters:
- name: test
type: string
default: aa
variables:
- name: a
value: ${{ parameters.test }}
pool:
vmImage: 'ubuntu-latest'
steps:
- script: echo $(a)
displayName: 'Run a one-line script'
- task: replacetokens@3
inputs:
rootDirectory: '$(build.sourcesdirectory)'
targetFiles: '**/*.xml'
encoding: 'auto'
writeBOM: true
actionOnMissing: 'warn'
keepToken: false
tokenPrefix: '#{'
tokenSuffix: '}#'
useLegacyPattern: false
enableTelemetry: true
Input value for parameter: changevalue
Result:
By the way, you also could use the file transform task. This task is to convert variables through files.
Upvotes: 1