WaelHamze / xrm-ci-framework

xRM CI Framework provides you with the tools automate the build and deployment of your CRM Solution. Using the framework to implement a fully automated DevOps pipeline will allow you to deploy more frequently with added consistency and quality.
MIT License
186 stars 117 forks source link

Scope issues when calling multiple scripts from one powershell session #251

Closed tdahnert closed 4 years ago

tdahnert commented 4 years ago

When I call the ExportSolution.ps1 and ImportSolution.ps1 from the same powershell session It's retaining the connection string from whichever script I called first and re-using it for my second call. I can call them in either order (Import then export) and it remembers the first connection I make instead of re-using it. It will continue to remember this connection string until I completely close out of powershell and re-open. If I then pass a different connection string in first, it will continue using that until I again close the session completely. I've been able to get around the issue by making the calls inside a Job instead. Because this is a different powershell session for each call it properly resolves the connection string and executes against the right CRM instance regardless of which call is first. Do you have any example of how to write a script to call the cmdlets so that they don't interfere with each other without resorting to jobs for each call?

This is how I was trying to invoke Invoke-Expression "& $commandExportFromdev"

This is how I can invoke successfully $Job = Start-Job -ScriptBlock { Invoke-Expression "& $using:JobCommand" }

tdahnert commented 4 years ago

After some more troubleshooting I found the missing RequireNewInstance=True in my connection string was the issue. Once I had the keyword to search on I looked through closed Issues and found a number of people struggling with the same issue. Would be helpful to add this to the wiki if possible.