Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging VSTS powershell scripts, locally

I am very new to PowerShell, so please be kind.

My scenario is this.

I have a bunch of PS scripts that works along my Build and Release definitions on VSTS/Azure DevOps.

I have a hard time understanding how I can debug these scripts locally because the scripts rely on certain "variables" or parameters.

E.g: Due to my lack of PS knowledge I do not understand how I can set these locally, instead of having them come from VSTS, when I actually run them from there.

Param(
  [string]$BinariesDirectory,
  [string]$SourcesDirectory,
  [string]$DeploymentConfiguration,
  [string]$Major,
  [string]$Minor,
  [string]$ChangesetNo,
  [string]$RevisionNumber
)

I struggle understanding how I should debug PowerShell scripts that run of VSTS, and how I feed those scripts the parameters it needs.

Many thanks!


2 Answers

You can simply assign values to it locally and hit the F5 button in the PowerShell ISE to debug the script:

Param(
  [string]$BinariesDirectory = 'c:\....',
  [string]$SourcesDirectory = 'c:\....',
  [string]$DeploymentConfiguration = 'c:\....',
  [string]$Major = '1',
  [string]$Minor = '3',
  [string]$ChangesetNo = '4',
  [string]$RevisionNumber = '4711'
)
like image 145
Martin Brandl Avatar answered Nov 21 '25 22:11

Martin Brandl


Here are two examples how you can do it locally:

#You can create a function and call it with the needed parameters like that:

function Use-Params {
param(
[String]$Variable1,
[String]$Variable2
)
    Write-Host "Variable1 value: $Variable1 "
    Write-Host "Variable2 value: $Variable2 "
}

Use-Params -Variable1 "Value 1" -Variable2 "Value 2"

#Or you just overwrite the variables in the script

function Use-Params {
param(
[String]$Variable1 = "Value 1",
[String]$Variable2 = "Value 2"
)
    Write-Host "Variable1 value: $Variable1 "
    Write-Host "Variable2 value: $Variable2 "
}

Use-Params
like image 20
guiwhatsthat Avatar answered Nov 21 '25 21:11

guiwhatsthat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!