Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pass script argument in Azure DevOps Pipeline which run a Powershell Script

Hi I have a simple Azure DevOps Pipeline

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:

- task: AzurePowerShell@5
  inputs:
    azureSubscription: 'Azure-DevOps'
    ScriptType: 'FilePath'
    ScriptPath: 'az-ps-scripts/session-07/vnet/vnet.ps1'
    ScriptArguments: '-RGNAME RunFmPp'
    azurePowerShellVersion: 'LatestVersion'
    workingDirectory: 'az-ps-scripts/session-07/vnet/'

As you can see it has a ScriptArguments: '-RGNAME RunFmPp' and it runs vnet.ps1 script.
But in fact, I do not know how can my vnet.ps1 script acces this argument from Azure DevOps.
This script create a Resource Group for Azure, I would like tho use -RGNAME here:

$rg = @{
    Name = $RGNAME
    Location = $vnetConf.Location
}
New-AzResourceGroup @rg -Force

But with $RGNAME it does not work, so does anyone know how can this script acces this argument from azure devops pipeline?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Declare your parameter(s) in a param() block at the top of your script:

param(
  [string]$RGNAME
)

$rg = @{
    Name = $RGNAME
    Location = $vnetConf.Location
}
New-AzResourceGroup @rg -Force
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading