Created
February 5, 2022 15:13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Azure PowerShell | |
# https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-powershell?view=azure-devops | |
# Run a PowerShell script within an Azure environment | |
- task: AzurePowerShell@5 | |
inputs: | |
azureSubscription: <YourServiceConnection> # Required. Name of Azure Resource Manager service connection | |
scriptType: 'inlineScript' # Optional. Options: filePath, inlineScript | |
#scriptPath: # Optional | |
inline: | # '# You can write your Azure PowerShell scripts inline here. # You can also pass predefined and custom variables to this script using arguments' # Optional | |
# Import needed modules | |
Import-Module SQLServer | |
Import-Module Az.Accounts -MinimumVersion 2.2.0 | |
# Install needed python modules | |
python -m pip install pyodbc | |
# Get an access token with the Service Pricipal used in the Azure DevOps Pipeline | |
$access_token = (Get-AzAccessToken -ResourceUrl https://database.windows.net).Token | |
# Set Variables as example | |
$server_name = <myserver.database.windows.net> | |
$database_name = <mydatabase> | |
$query = <SELECT * FROM dbo.Table> | |
python.exe 'python-script-with-pyodbc.py' -server_name $server_name -access_token $access_token | |
#scriptArguments: # Optional | |
#errorActionPreference: 'stop' # Optional. Options: stop, continue, silentlyContinue | |
#failOnStandardError: false # Optional | |
azurePowerShellVersion: 'latestVersion' # Required. Options: latestVersion, otherVersion | |
#preferredAzurePowerShellVersion: # Required when azurePowerShellVersion == OtherVersion | |
#pwsh: true # Optional. If true, then will use PowerShell Core pwsh.exe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment