-
Notifications
You must be signed in to change notification settings - Fork 1
/
streamLogs.yml
59 lines (54 loc) · 1.97 KB
/
streamLogs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
parameters:
- name: azureSubscription
type: string
- name: storageAccountName
type: string
- name: storageAccountRG
type: string
- name: storageAccountQueue
type: string
stages:
- stage: streamLogs
condition: always()
jobs:
- job: streamLogs
pool:
vmImage: windows-2019
steps:
- task: AzurePowerShell@4
condition: succeeded()
displayName: Add Pipeline Context to Queue
inputs:
azureSubscription: ${{ parameters.azureSubscription }}
scriptType: inlineScript
inline: |
# get current pipeline run context
$hash = @{};
$hash.add("definitionId", "$(System.DefinitionId)");
$hash.add("runId", "$(Build.BuildId)");
$json = $hash | ConvertTo-Json -Depth 10 -Compress;
# get storage account and key
$sa = Get-AzStorageAccount -ResourceGroupName "${{ parameters.storageAccountRG }}" -Name "${{ parameters.storageAccountName }}";
$saKey = $($sa | Get-AzStorageAccountKey).Value[0];
# storage queue
try
{
$ctx = New-AzStorageContext -StorageAccountName $sa.storageAccountName -StorageAccountKey $saKey;
$queue = Get-AzStorageQueue –Name "${{ parameters.storageAccountQueue }}" –Context $ctx;
}
catch [exception]
{
throw "Failed to get storage account queue. $($_)";
}
# put message on queue
try
{
$message = [Microsoft.Azure.Storage.Queue.CloudQueueMessage]::new($json);
$queue.CloudQueue.AddMessageAsync($message);
}
catch [exception]
{
throw "Failed to put message on queue. $($_)";
}
errorActionPreference: stop
azurePowerShellVersion: latestVersion