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 |
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 |
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
import pyodbc | |
import struct | |
def use_token(server_name, access_token): | |
connection_string = 'Driver={ODBC Driver 17 for SQL Server};server='+server_name+';database=master;' | |
SQL_COPT_SS_ACCESS_TOKEN = 1256 | |
exptoken = b'' | |
for i in bytes(access_token, "UTF-8"): | |
exptoken += bytes({i}) |
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
import requests | |
def send_error_to_teams(error_message, webhook_url): | |
""" This function will use the requests library to make a POST request to the webhook URL with the error message as the payload """ | |
payload = { | |
"text": error_message | |
} | |
response = requests.post(webhook_url, json=payload) | |
response.raise_for_status() |
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
WEBHOOK_URL = "your_teams_webhook_url" | |
@send_error_to_teams_decorator(WEBHOOK_URL) | |
def my_function(): | |
try: | |
raise Exception("This try block always fails!") | |
except Exception as e: | |
raise ValueError(f"ValueError: {str(e)}") | |
my_function() |
OlderNewer