Search code examples
powershellazure-devopssession-variablesrelease-management

how to read the session variables with special chars, spaces ect in powershell on target machine task in tfs 2015


We are using Release Management(client/server) for our deployments today and we have both Agent based and vNext Release templates and we have powershell code which takes care of these deployments. Now, we are migrating to the web version of release management in tfs 2015 , we want to use "powershell on target Machine" task to invoke our base script(which then imports other PS modules) which takes care of the deployment. The problem we are facing is with variables , we need to pass lot of variables to our code , these variables will then be transformed and replace in our config files. these variables have special characters and spaces etc and when we pass these variables in Session variables the deployment is failing because of the spl char or space etc Is there a way where we can pass the variables to our code with out getting failure.

we have added a inline powershell task to our release which will add all the variables to an xml file and this file will be sitting on build server , then we are adding windows file copy task to move this file to target server one more task powershell on target machine which invokes our base script in which we have updated to read the variables from xml file. but the problem with this is that we ended up adding 4 tasks in our release to take care of one component in Release Management and some of our releases are quite complicated where we have ~20 components and if we have to migrate this to web based release management we have to add ~80 steps which will add lot of confusion. is there a better way of doing this? Please let me know if i make any sense or if more details are required Variables screeshot

attached a screenshot of the variables which i am trying to pass to session variables in powershell on target machine task. these variables has '=' in them and when these are passed to the task i get the following error "2019-02-11T17:11:19.9812595Z ##[error]The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Found value 'Source' with no corresponding key"


Solution

  • we were going in the wrong direction of reading the variables through session variables we have found out that there is an api which makes all the release variables available.

    https://{tfsurl}/{collection}/{project}/_apis/release/releases/{releaseId}?api-version=3.0-preview.1

    we have then updated our code to get the variables based on the environment