5

I'm developing a quite large automatic build in TFS2017 with a local VSTS build machine. My custom tasks will be mostly in PowerShell.

The inline PowerShell task handles only 500 or so characters and is too small to use for most tasks. Right now I'm editing my Powershell script, check it in, test run, read log for errors, correct, check in again and so on.

This is a bit tedious and I wonder if there are any options. I would like to avoid checking in each change in the script. Are there any options like executing my Powershell tasks from a network location during development of the build process?

1
  • trying to "avoid checking in each change in the script" is bad practice and will lead you into trouble. Better to do it properly with correct code check-ins, and introduce automatic testing within the pipeline - to take away the manual error-checking in the logs. Commented Dec 11, 2021 at 1:25

5 Answers 5

3

You can use dot sourcing with your UNC path:

PS> . \\server\path\to\your\scriptmcscript.ps1

or use the invocation operator:

& \\server\path\to\your\scriptmcscript.ps1
Sign up to request clarification or add additional context in comments.

Comments

1

You can specify UNC file path in PowerShell task.

You also can store the script files in a server (e.g. FTP), then download the file to working directory during build through PowerShell or others task.

On the other hand, there is PowerShell on Target machines task that can execute PowerShell scripts on remote machines.

1 Comment

Thanks! I never knew that you could specify a file path in the PowerShell task. Executing from a UNC path did not work for me for some security reason, but copy the script to a local directory on the build machine and then executing it worked.
1

This is the only way that works for me, call PowerShell from a .batch script with execution policy set to bypass (scope - process only)

-NonInteractive = do not prompt for confirm
-NoProfile = run under system context

powershell.exe -NoProfile -ExecutionPolicy Bypass -NonInteractive -Command C:\Users\User\Script.ps1

Comments

1

When you try using a SQL Server job, none of the mentioned will work. Please try the below command; it works flawlessly. You can try adding n number of input params

powershell.exe -ExecutionPolicy Bypass -Command "& { \\Shared\Share\IncrementalProcessing\DimProcessing.ps1 -serverName 'FROST' -databaseName 'Cube' -dir 'C:\SQLFiles\IncrementalProcessingCubes' }"

Comments

0

You can use UNC path for the file with Powershell Task. Or you could use the Powershell on target machine to run it.

But be careful about your choice. You have to keep in mind that who is running your script is the build/deployment agent. So while you are running it in your corporate network everything will be fine, because your agent can see your UNC path.

The moment you use that agent on a machine outside your network you will have to think about another solution, which may include saving your powershell file to a repo like Git or TFVC and then download the file to the local computer where you are running the agent.

2 Comments

Yes, the UNC path will only be used during development. When the build process goes into production all the PowerShell scripts will be checked into TFVC and executed from there.
I would then recommend that you start using the powershell scripts from TFVC from the beginning, to eliminate risks to have different scripts running and to have the same deployment tasks on different environments. Just my suggestion. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.