|
| 1 | +parameters: |
| 2 | + AssetName: '' |
| 3 | + AssetVersion: '' |
| 4 | + TriggerSubscrption: false |
| 5 | + IsGitHubRepo: true |
| 6 | + |
| 7 | +steps: |
| 8 | + - task: PowerShell@2 |
| 9 | + displayName: Check prerequisites |
| 10 | + inputs: |
| 11 | + targetType: 'inline' |
| 12 | + script: | |
| 13 | + Write-Host "Pipeline Variable 'MaestroToken' and 'MaestroUri' must have a value" |
| 14 | + Write-Host "##vso[task.complete result=Failed;]DONE" |
| 15 | + condition: or(eq(variables['MaestroUri'], ''), eq(variables['MaestroToken'], '')) |
| 16 | + |
| 17 | + - task: PowerShell@2 |
| 18 | + displayName: Build JsonBody |
| 19 | + inputs: |
| 20 | + targetType: 'inline' |
| 21 | + script: | |
| 22 | + . .\eng\common\MaestroHelpers.ps1 |
| 23 | + |
| 24 | + $jsonBase = @{} |
| 25 | +
|
| 26 | + $assetList = New-Object System.Collections.ArrayList |
| 27 | + $assetList.Add( |
| 28 | + @{ |
| 29 | + "name"="${{ parameters.AssetName }}"; |
| 30 | + "version"="${{ parameters.AssetVersion }}"; |
| 31 | + "nonShipping"=$false; |
| 32 | + "locations"=$null |
| 33 | + } |
| 34 | + ) |
| 35 | +
|
| 36 | + # These fields below are unused but can be enabled in the future |
| 37 | + # $locationList = New-Object System.Collections.ArrayList |
| 38 | + # $locationList.Add(@{"location"="maestroTestValue";"type"="none"}) |
| 39 | +
|
| 40 | + # $dependenciesList = New-Object System.Collections.ArrayList |
| 41 | + # $dependenciesList.Add( |
| 42 | + # @{ |
| 43 | + # "buildId"=0; |
| 44 | + # "isProduct"=$true; |
| 45 | + # "timeToInclusionInMinutes"=0; |
| 46 | + # } |
| 47 | + # ) |
| 48 | +
|
| 49 | + # $incoherenciesList = New-Object System.Collections.ArrayList |
| 50 | + # $incoherenciesList.Add( |
| 51 | + # @{ |
| 52 | + # "name"="maestroTestValue"; |
| 53 | + # "version"="maestroTestValue"; |
| 54 | + # "repository"="maestroTestValue"; |
| 55 | + # "commit"="maestroTestValue"; |
| 56 | + # } |
| 57 | + # ) |
| 58 | +
|
| 59 | + Write-Host "collectionuri: $(System.CollectionUri)" |
| 60 | + $devOpsAccount = ExtractOrgFromAzureDevOpsCollectionUri '$(System.CollectionUri)' |
| 61 | + Write-Host "reposiitory: $(Build.Repository.Uri)" |
| 62 | + Write-Host "account: " $devOpsAccount |
| 63 | + |
| 64 | + $gitHubRepo = "" |
| 65 | + $azureDevOpsRepo = "" |
| 66 | + if ('${{ parameters.IsGitHubRepo }}' -eq 'true') |
| 67 | + { |
| 68 | + $gitHubRepo = "$(Build.Repository.Uri)" |
| 69 | + $azureDevOpsRepo = "$(Build.Repository.Uri)" # Maestro expects this to be always set |
| 70 | + } |
| 71 | + if ('${{ parameters.IsGitHubRepo }}' -ne 'true') |
| 72 | + { |
| 73 | + $azureDevOpsRepo = "$(Build.Repository.Uri)" |
| 74 | + } |
| 75 | +
|
| 76 | + $jsonBase = |
| 77 | + @{ |
| 78 | + "commit"="$(Build.SourceVersion)"; |
| 79 | + "assets"=$assetList; |
| 80 | + "dependencies"=$null; |
| 81 | + "azureDevOpsBuildId"=$(Build.BuildId); |
| 82 | + "azureDevOpsBuildDefinitionId"=$(System.DefinitionId); |
| 83 | + "azureDevOpsAccount"=$devOpsAccount; |
| 84 | + "azureDevOpsProject"="$(System.TeamProject)"; |
| 85 | + "azureDevOpsBuildNumber"="$(Build.BuildNumber)"; |
| 86 | + "azureDevOpsRepository"=$azureDevOpsRepo; |
| 87 | + "azureDevOpsBranch"="$(Build.SourceBranch)"; |
| 88 | + "gitHubRepository"=$gitHubRepo; |
| 89 | + "gitHubBranch"="$(Build.SourceBranch)"; |
| 90 | + "released"=$true; |
| 91 | + "stable"=$true |
| 92 | + "incoherencies"=$null; |
| 93 | + } |
| 94 | +
|
| 95 | + $jsonBase | ConvertTo-Json -Depth 10 | Out-File '$(Build.SourcesDirectory)\eng\common\maestro-build.json' |
| 96 | + $body = Get-Content -Raw -Path '$(Build.SourcesDirectory)\eng\common\maestro-build.json' |
| 97 | + Write-host $body |
| 98 | +
|
| 99 | + - task: powershell@2 |
| 100 | + displayName: 'Post build to Maestro' |
| 101 | + inputs: |
| 102 | + targetType: filePath |
| 103 | + filePath: eng\common\MaestroPostRequest.ps1 |
| 104 | + arguments: -url '$(MaestroUri)' -Token '$(MaestroToken)' -api '/api/builds' -jsonBodyPath '$(Build.SourcesDirectory)\eng\common\maestro-build.json' |
| 105 | + |
| 106 | + - ${{ if eq(parameters.TriggerSubscrption, 'true') }}: |
| 107 | + - task: powershell@2 |
| 108 | + displayName: 'Publish Build to Default Channel' |
| 109 | + inputs: |
| 110 | + targetType: 'inline' |
| 111 | + script: | |
| 112 | + # Get the id of the default channel of this branch |
| 113 | + $api = "/api/default-channels" |
| 114 | + $response = &".\eng\common\MaestroGetRequest.ps1" -url '$(MaestroUri)' -Token '$(MaestroToken)' -api $api -queryParameters '&repository=$(Build.Repository.Uri)&branch=$(Build.SourceBranch)' |
| 115 | + $jsonObj = ConvertFrom-Json $response.Content |
| 116 | + $channelId = $jsonObj.channel.id |
| 117 | + if ([string]::IsNullOrEmpty($channelId)) |
| 118 | + { |
| 119 | + Write-Host "Error: Default channel not found. Please use darc add-default-channel to add a default channel for this repo and branch" |
| 120 | + Write-Host "##vso[task.complete result=SucceededWithIssues;]DONE" |
| 121 | + } |
| 122 | + else |
| 123 | + { |
| 124 | + # Get the id of the build posted earlier |
| 125 | + $api = "/api/builds" |
| 126 | + $response = &".\eng\common\MaestroGetRequest.ps1" -url '$(MaestroUri)' -Token '$(MaestroToken)' -api $api -queryParameters '&repository=$(Build.Repository.Uri)&commit=$(Build.SourceVersion)' |
| 127 | + $jsonObj = ConvertFrom-Json $response.Content |
| 128 | + $buildId = $jsonObj.id |
| 129 | + if ([string]::IsNullOrEmpty($buildId)) |
| 130 | + { |
| 131 | + Write-Host "Error: build not found in Maestro" |
| 132 | + Write-Host "##vso[task.complete result=Failed;]DONE" |
| 133 | + } |
| 134 | +
|
| 135 | + # AddBuildToChannel with the corresponding build id and channel id |
| 136 | + $api = "/api/channels/" + $channelId + "/builds/" + $buildId |
| 137 | + $response = &".\eng\common\MaestroPostRequest.ps1" -url '$(MaestroUri)' -Token '$(MaestroToken)' -api $api -jsonBodyPath '' |
| 138 | +
|
| 139 | + # Get the list of subscriptions on the channel |
| 140 | + $api = "/api/subscriptions" |
| 141 | + $queryParams = "&channelId=" + $channelId |
| 142 | + $response = &".\eng\common\MaestroGetRequest.ps1" -url '$(MaestroUri)' -Token '$(MaestroToken)' -api $api -queryParameters $queryParams |
| 143 | + $jsonObj = ConvertFrom-Json $response.Content |
| 144 | + foreach ($sub in $jsonObj) |
| 145 | + { |
| 146 | + # Trigger the subscription |
| 147 | + $id = $sub.id |
| 148 | + Write-Host "Triggering subscription on " $id |
| 149 | + # bar-build-id is always 0 |
| 150 | + $api = "/api/subscriptions/" + $id + "/trigger" |
| 151 | + $response = &".\eng\common\MaestroPostRequest.ps1" -url '$(MaestroUri)' -Token '$(MaestroToken)' -api $api -jsonBodyPath '' -queryParameters '&bar-build-id=0' |
| 152 | + } |
| 153 | + } |
| 154 | +
|
0 commit comments