PSDeploy icon indicating copy to clipboard operation
PSDeploy copied to clipboard

Use Task to Setup Enviroment Variables

Open mmattes opened this issue 8 years ago • 2 comments

Hi,

it took me a while to figure out how I can use tasks to set Enviroment Variables which can be used during the whole deployment. I first tried the following

Deploy {

    By Task Set-Enviroment {        
     	$Env:Enviroment = "Dev"
        $Env:InstPath = "C:\Web\Precompiled\$Env:Enviroment.Website"        
        Tagged Dev
    }
    By Noop Test {
    	FromSource dist
    	To $Env:InstPath
    	DependingOn Set-Enviroment
    }
}

unfortunately this did not work out "By Noop Test" did not know anything about my enviroment variables. What worked out for me is to put the Enviroment variable within the task into the FromSource part like that:

Deploy {

    By Task Set-Enviroment {        
    	FromSource {
    		$Env:Enviroment = "Dev"
        	$Env:InstPath = "C:\Web\Precompiled\$Env:Enviroment.Website"        	
    	}     	
        Tagged Dev
    }
    By Noop Test {
    	FromSource dist
    	To $Env:InstPath
    	DependingOn Set-Enviroment
    }
}

The documentation does not say anything about that. I would like to complete the documentation but I dont know how it acutally is intended to be working? Is my approach by putting it into the FromSource correct?

mmattes avatar Aug 04 '17 20:08 mmattes

Hiyo!

Strange! I'll play around with it when I have a few minutes, might be a little while (about to head out of town).

Long story short, each layer dot sources the scriptblock... so in your working example:

  • Deploy sets up collection and...
  • Dot sources scriptblock for By Task
  • Dot sources nested FromSource
  • Dot sources scriptblock for By Noop

Something might be off in the logic - it seems like you should see the env bits you set even in your first example, as long as the task runs first, but there might be some oddity in the code.

Cheers!

RamblingCookieMonster avatar Aug 05 '17 13:08 RamblingCookieMonster

Actually the only way it did work out for me in the end is to setup the enviroment variables in a powershell script before i call the Invoke-PSDeploy command. I have not managed to setup enviroment variables in a task so that another part of the psdeploy.ps1 file could pic the variables up then.

mmattes avatar Aug 05 '17 13:08 mmattes