Reputation: 91
We had one situation where we needs to change some variables based on Targets within Deployment Groups.
Deployment Stage runs, depending upon its execution target Machine, How can we pass different variable values?
We need to transform the App Settings (replace URL) file before deploying it to targets.
Upvotes: 0
Views: 427
Reputation: 91
I've added Powershell script step in release pipeline to get the Agent Machine Name.
$agentMachineName = $env:AGENT_MACHINENAME
Write-Host "##vso[task.setvariable variable=server_name]$agentMachineName"
And using server_name variable to replace the URL with agentMachineName at runtime.
Upvotes: 0
Reputation: 35464
Based on your requirement, you need to transform the variables value in App Settings file based on the target machine.
To transform the variables value in App Settings file, you can use the built in task: File transform task.
You can set the Pipeline variable and update the variable of app settings file in the task.
For example:
- task: FileTransform@1
displayName: 'File Transform: '
inputs:
folderPath: 'folder path'
fileType: json
targetFiles: appsettings.json
To set the variable based on execution target Machine, you can use the predefined variable: Agent.MachineName
and Condition.
For example:
- task: FileTransform@1
displayName: 'File Transform: '
inputs:
folderPath: 'folder path'
fileType: json
targetFiles: appsettings.json
condition: eq(variables['Agent.MachineName'], 'machinename')
Upvotes: 1