-
Notifications
You must be signed in to change notification settings - Fork 36
/
azure-pipelines.yml
87 lines (80 loc) · 3.34 KB
/
azure-pipelines.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
parameters:
- name: cancelPriorDeployments
displayName: Cancel prior deployments
type: boolean
default: true
variables:
- group: fssnip-variable-group
- name: cancelPriorDeployments
value: '${{ parameters.cancelPriorDeployments }}'
- name: devOpsApiVersion
value: 6.0
trigger:
- master
stages:
- stage: CancelPriorDeploymentsStage
displayName: Cancel prior deployments
condition: eq(variables.cancelPriorDeployments, 'true')
jobs:
- job: CancelPriorDeploymentsJob
displayName: List builds, cancel prior in progress
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: none
- task: PowerShell@2
displayName: Powershell AzDO Invoke-RestMethod
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
inputs:
targetType: inline
script: |
$header = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
$buildsUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds?api-version=$(devOpsApiVersion)"
Write-Host "GET $buildsUrl"
$builds = Invoke-RestMethod -Uri $buildsUrl -Method Get -Header $header
$buildsToStop = $builds.value.Where({ ($_.status -eq 'inProgress') -and ($_.definition.name -eq "$(Build.DefinitionName)") -and ($_.id -lt $(Build.BuildId)) })
ForEach($build in $buildsToStop)
{
$urlToCancel = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds/$($build.id)?api-version=$(devOpsApiVersion)"
$body = @{ status = "cancelling" } | ConvertTo-Json
Write-Host "PATCH $urlToCancel"
Invoke-RestMethod -Uri $urlToCancel -Method Patch -Header $header -ContentType application/json -Body $body
}
- stage: BuildAndDeploy
displayName: Build and deploy
jobs:
- job: BuildAndDeploy
displayName: Build And Deploy
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
useGlobalJson: true
- script: dotnet tool restore
- script: dotnet paket restore
- script: dotnet fake run build.fsx %*
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '7.0.x'
# This restrictive global.json is needed for the build commands above, but it would prevent the .fsx in the next task from running.
- script: rm global.json
- task: AzureCLI@2
inputs:
azureSubscription: $(AZURE_SUBSCRIPTION)
scriptType: 'pscore'
scriptLocation: 'inlineScript'
# The deploy.fsx writes it's output to a text file, contents of that is then read into $key
# and the the last line command writes that value into the FSSNIP_STORAGE_CONNECTION_STRING variable
# in the fssnip-variable-group group. This is a hackaround to pass output of this pipeline to the next.
# The '> $null' disables echoing of the last line command output.
inlineScript: |
dotnet fsi deploy.fsx
$key=Get-Content 'deployed_storage_key.txt' -Raw
az pipelines variable-group variable update --group-id $(group_id) --name FSSNIP_STORAGE_CONNECTION_STRING --value $key --org https://dev.azure.com/compositional-it --project 'FSharp Snippets' > $null
env:
RECAPTCHA_SECRET: $(RECAPTCHA_SECRET)
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)