1+ #  Create a VS insertion (DotNet-MSBuild-Trusted -> VS) from a CI run on main or any servicing branch.
2+ #  To achieve insertion automation, this pipeline definition yml has to be on servicing branches and main.
3+ 
4+ 
5+ #  Runs in 3 modes: 
6+ #  1. daily main insertion from latest main CI.
7+ #    - can be disabled in the UI by adding a custom schedule for any branch. 
8+ #  2. trigger insert as a followup to a servicing CI run.
9+ #    - can be disabled in the UI by adding a custom CI trigger.
10+ #  3. manual insertion - select manually the TargetBranch and inserted CI run.
11+ trigger : none 
12+ pr : none 
13+ name : $(Date:yyyyMMdd).$(Rev:r) 
14+ 
15+ schedules :
16+   - cron : ' 0 3 * * 1-5' #  Runs every weekday at 3AM UTC
17+     displayName : Daily VS insertion main 
18+     branches :
19+       include :
20+         - main 
21+     always : false  #  Don't run if there are no code changes
22+ 
23+ resources :
24+   pipelines :
25+   - pipeline : ' MSBuild' 
26+     project : ' DevDiv' 
27+     source : ' MSBuild' 
28+     branch : main  #  for daily main scheduled insertion
29+     trigger :
30+       branches :
31+         include : #  trigger as a followup to servicing CI
32+           - vs* 
33+   repositories :
34+   - repository : 1ESPipelineTemplates 
35+     type : git 
36+     name : 1ESPipelineTemplates/1ESPipelineTemplates 
37+     ref : refs/tags/release 
38+ 
39+ parameters :
40+   - name : TargetBranch 
41+     default : auto 
42+     type : string 
43+     displayName : ' Insertion Target Branch (select for manual insertion)' 
44+     values :
45+       - auto 
46+       - main 
47+       - rel/d17.13 
48+       - rel/d17.12 
49+       - rel/d17.11 
50+       - rel/d17.10 
51+       - rel/d17.8 
52+       - rel/d17.6 
53+       - rel/d17.3 
54+       - rel/d17.0 
55+   - name : DropRetentionDays 
56+     default : 183 
57+     type : number 
58+     displayName : ' Drop Retention Days (do not set to < 90)' 
59+ 
60+ variables :
61+   #  `auto` should work every time and selecting a branch in parameters is likely to fail due to incompatible versions in MSBuild and VS
62+   - name : AutoInsertTargetBranch 
63+     ${{ if eq(variables['Build.SourceBranchName'], 'vs17.13') }} :
64+       value : ' rel/d17.13' 
65+     ${{ elseif eq(variables['Build.SourceBranchName'], 'vs17.12') }} :
66+       value : ' rel/d17.12' 
67+     ${{ elseif eq(variables['Build.SourceBranchName'], 'vs17.11') }} :
68+       value : ' rel/d17.11' 
69+     ${{ elseif eq(variables['Build.SourceBranchName'], 'vs17.10') }} :
70+       value : ' rel/d17.10' 
71+     ${{ elseif eq(variables['Build.SourceBranchName'], 'vs17.8') }} :
72+       value : ' rel/d17.8' 
73+     ${{ elseif eq(variables['Build.SourceBranchName'], 'vs17.6') }} :
74+       value : ' rel/d17.6' 
75+     ${{ elseif eq(variables['Build.SourceBranchName'], 'vs17.3') }} :
76+       value : ' rel/d17.3' 
77+     ${{ elseif eq(variables['Build.SourceBranchName'], 'vs17.0') }} :
78+       value : ' rel/d17.0' 
79+     ${{ elseif eq(variables['Build.SourceBranchName'], 'main') }} :
80+       value : ' main' 
81+     ${{ else }} :
82+       value : ' ' 
83+   - name : InsertTargetBranch 
84+     ${{ if not(eq(parameters.TargetBranch, 'auto')) }} :
85+       value : ${{ parameters.TargetBranch }} 
86+     ${{ else }} :
87+       value : $(AutoInsertTargetBranch) 
88+   - name :  TeamName 
89+     value : msbuild 
90+   - name : TeamEmail 
91+ 92+   - name : MSBuild_CI_BuildNumber 
93+     value : $(resources.pipeline.MSBuild.runName) 
94+   - name : MSBuild_CI_SourceVersion 
95+     value : $(resources.pipeline.MSBuild.sourceCommit) 
96+   - name : ArtifactPackagesPath 
97+     value : $(Build.ArtifactStagingDirectory)/PackageArtifacts 
98+   
99+   - name : MSBuildPackagePattern  
100+     value : ' $(ArtifactPackagesPath)/Microsoft.Build.*.nupkg' 
101+   - name : StringToolsPackagePattern 
102+     value : ' $(ArtifactPackagesPath)/Microsoft.NET.StringTools*.nupkg' 
103+   - name : ExternalAPIsPackagePattern 
104+     value : ' $(ArtifactPackagesPath)/VS.ExternalAPIs.*.nupkg' 
105+   #  servicing branches until 17.12 also include Microsoft.Build.Engine and Microsoft.Build.Conversion.Core
106+   - name : EngineIncludedProps 
107+     value : VS.ExternalAPIs.MSBuild=$(MSBuild_ExtApisPackageVersion);Microsoft.Build=$(MicrosoftNETStringToolsPackageVersion);Microsoft.Build.Conversion.Core=$(MicrosoftNETStringToolsPackageVersion);Microsoft.Build.Engine=$(MicrosoftNETStringToolsPackageVersion);Microsoft.Build.Framework=$(MicrosoftNETStringToolsPackageVersion);Microsoft.Build.Tasks.Core=$(MicrosoftNETStringToolsPackageVersion);Microsoft.Build.Utilities.Core=$(MicrosoftNETStringToolsPackageVersion);Microsoft.NET.StringTools=$(MicrosoftNETStringToolsPackageVersion) 
108+   - name : NoEngineProps 
109+     value : VS.ExternalAPIs.MSBuild=$(MSBuild_ExtApisPackageVersion);Microsoft.Build=$(MicrosoftNETStringToolsPackageVersion);Microsoft.Build.Framework=$(MicrosoftNETStringToolsPackageVersion);Microsoft.Build.Tasks.Core=$(MicrosoftNETStringToolsPackageVersion);Microsoft.Build.Utilities.Core=$(MicrosoftNETStringToolsPackageVersion);Microsoft.NET.StringTools=$(MicrosoftNETStringToolsPackageVersion) 
110+ 
111+ extends :
112+   template : v1/1ES.Official.PipelineTemplate.yml@1ESPipelineTemplates 
113+   parameters :
114+     pool :
115+       name : VSEngSS-MicroBuild2022-1ES 
116+     customBuildTags :
117+     - ES365AIMigrationTooling-Release 
118+     stages :
119+     - stage : RetainBuild 
120+       displayName : Retain build 
121+       jobs :
122+       - job : Job_1 
123+         displayName : Run on agent 
124+         condition : succeeded() 
125+         timeoutInMinutes : 0 
126+         steps :
127+           #  Check that InsertTargetBranch is valid before running anything else.
128+         - task : PowerShell@2 
129+           name : CheckInsertTargetBranch 
130+           inputs :
131+             targetType : inline 
132+             script : | 
133+               if ("$(InsertTargetBranch)" -eq "") { 
134+                 Write-Error "InsertTargetBranch is not set, this means your're not inserting from main or a valid servicing branch." 
135+                 exit 1 
136+               } 
137+ #  the insertion source branch corresponds to the branch on which the MSBuild pipeline ran
138+         - task : PowerShell@2 
139+           name : SetSourceBranchName 
140+           inputs :
141+             targetType : inline 
142+             script : | 
143+               # Extract the last section after the last '/' 
144+               $fullBranch = "$(resources.pipeline.MSBuild.sourceBranch)" 
145+               $branchSegments = $fullBranch -split '/' 
146+               $branch = $branchSegments[-1] 
147+               Write-Host "Setting source branch to '$branch'" 
148+               Write-Host "##vso[task.setvariable variable=SourceBranchName;isoutput=true]$branch" 
149+ task : MicroBuildRetainVstsDrops@1 
150+           name : MicroBuildRetainVstsDrops_2 
151+           displayName : Retain VSTS Drops 
152+           inputs :
153+             DropNames : Products/DevDiv/DotNet-msbuild-Trusted/$(SetSourceBranchName.SourceBranchName)/$(MSBuild_CI_BuildNumber) 
154+             AccessToken : $(System.AccessToken) 
155+             DropServiceUri : https://devdiv.artifacts.visualstudio.com/DefaultCollection 
156+             DropRetentionDays : ${{ parameters.DropRetentionDays }} 
157+     - stage : VSInsertion 
158+       displayName : VS insertion 
159+       dependsOn : RetainBuild 
160+       variables :
161+         SourceBranchName : $[ stageDependencies.RetainBuild.Job_1.outputs['SetSourceBranchName.SourceBranchName'] ] 
162+         VSDropPath : https://vsdrop.corp.microsoft.com/file/v1/Products/DevDiv/DotNet-msbuild-Trusted/$(SourceBranchName)/$(MSBuild_CI_BuildNumber) 
163+         VSManVersionSuffix : $(MSBuild_ExtApisPackageVersion)+$(MSBuild_CI_SourceVersion) 
164+         StandardVSManPath : Microsoft.Build.vsman{$(VSManVersionSuffix)}=$(VSDropPath);Microsoft.Build.vsman 
165+         Arm64VSManPath : Microsoft.Build.Arm64.vsman{$(VSManVersionSuffix)}=$(VSDropPath);Microsoft.Build.Arm64.vsman 
166+         UnGACVSManPath : Microsoft.Build.UnGAC.vsman=$(VSDropPath);Microsoft.Build.UnGAC.vsman 
167+         InsertJsonValues : $(StandardVSManPath),$(Arm64VSManPath),$(UnGACVSManPath) 
168+         InsertConfigValues : VS.ExternalAPIs.MSBuild=$(MSBuild_ExtApisPackageVersion) 
169+         InsertCustomScriptExecutionCommand : $(Pipeline.Workspace)\xsd\Update-MSBuildXsds.ps1 
170+         InsertDescription : Insert MSBuild $(MSBuild_CI_BuildNumber) from the branch $(SourceBranchName) at commit $(MSBuild_CI_SourceVersion). Corresponding package version is $(MSBuild_ExtApisPackageVersion) 
171+         InsertPayloadName : ' MSBuild $(SourceBranchName) $(MSBuild_ExtApisPackageVersion)' 
172+       jobs :
173+       - job : PushPackagesAndInsert 
174+         displayName : Push Packages and Insert VS payload 
175+         condition : succeeded() 
176+         timeoutInMinutes : 0 
177+         templateContext :
178+           inputs :
179+           - input : pipelineArtifact 
180+             pipeline : ' MSBuild' 
181+             artifactName : ' xsd' 
182+             targetPath : ' $(Pipeline.Workspace)/xsd' 
183+           - input : pipelineArtifact 
184+             pipeline : ' MSBuild' 
185+             artifactName : ' PackageArtifacts' 
186+             targetPath : ' $(Build.ArtifactStagingDirectory)/PackageArtifacts' 
187+             #  the CI build creates a sourcebuild intermediate package that is not signed, remove it to avoid warning from Guardian
188+             itemPattern : | 
189+               ** 
190+               !**/Microsoft.SourceBuild.Intermediate*.nupkg 
191+ steps :
192+         - task : Powershell@2 
193+           name : PwshMungeExternalAPIsPkgVersion 
194+           displayName : Munge ExternalAPIs package version 
195+           inputs :
196+             targetType : inline 
197+             script : | 
198+               $folder = "$(Build.ArtifactStagingDirectory)/PackageArtifacts/VS.ExternalAPIs.*.nupkg" 
199+               $packageFile = Get-ChildItem -Path $folder -Filter VS.ExternalAPIs.*.nupkg | Select-Object -First 1 
200+               $packageVersion = $packageFile.BaseName.TrimStart("VS.ExternalAPIs.MSBuild") 
201+               Write-Host "Setting MSBuild_ExtApisPackageVersion to '$packageVersion'" 
202+               Write-Host "##vso[task.setvariable variable=MSBuild_ExtApisPackageVersion]$($packageVersion)" 
203+               $folder = "$(Build.ArtifactStagingDirectory)/PackageArtifacts/Microsoft.NET.StringTools*.nupkg" 
204+               $packageFile = Get-ChildItem -Path $folder -Filter Microsoft.NET.StringTools*.nupkg | Select-Object -First 1 
205+               $packageVersion = $packageFile.BaseName.TrimStart("Microsoft.NET.StringTools") 
206+               Write-Host "Setting MicrosoftNETStringToolsPackageVersion to '$packageVersion'" 
207+               Write-Host "##vso[task.setvariable variable=MicrosoftNETStringToolsPackageVersion]$($packageVersion)" 
208+               if ("$(InsertTargetBranch)" -in @("vs17.0", "vs17.3", "vs17.6", "vs17.8", "vs17.10", "vs17.11", "vs17.12")) 
209+               { 
210+                   Write-Host "##vso[task.setvariable variable=InsertPackagePropsValues]$($EngineIncludedProps)" 
211+               } 
212+               else 
213+               { 
214+                   Write-Host "##vso[task.setvariable variable=InsertPackagePropsValues]$($NoEngineProps)" 
215+               } 
216+ task : 1ES.PublishNuGet@1 
217+           displayName : ' Push MSBuild CoreXT packages' 
218+           inputs :
219+             packageParentPath : ' $(Build.ArtifactStagingDirectory)' 
220+             packagesToPush : $(MSBuildPackagePattern);$(StringToolsPackagePattern);$(ExternalAPIsPackagePattern) 
221+             nuGetFeedType : internal 
222+             publishVstsFeed : VS 
223+             allowPackageConflicts : true 
224+         - template : /azure-pipelines/WIFtoPATauth.yml@self 
225+           parameters :
226+             wifServiceConnectionName : azure-public/vside package push 
227+             deadPATServiceConnectionId : 42175e93-c771-4a4f-a132-3cca78f44b3b 
228+         - task : 1ES.PublishNuGet@1 
229+           displayName : ' Push MSBuild packages to VSSDK' 
230+           inputs :
231+             packageParentPath : ' $(Build.ArtifactStagingDirectory)' 
232+             packagesToPush : $(MSBuildPackagePattern);$(StringToolsPackagePattern) 
233+             nuGetFeedType : external 
234+             publishFeedCredentials : azure-public/vssdk 
235+             allowPackageConflicts : true 
236+         - task : PowerShell@2 
237+           name : PrintTargetBranch 
238+           inputs :
239+             targetType : inline 
240+             script : | 
241+               Write-Host "InsertTargetBranch: $(InsertTargetBranch)" 
242+ task : MicroBuildInsertVsPayload@4 
243+           name : MicroBuildInsertVsPayload_4 
244+           displayName : Insert VS Payload 
245+           inputs :
246+             LinkWorkItemsToPR : true 
247+             TeamName : $(TeamName) 
248+             TeamEmail : $(TeamEmail) 
249+             TargetBranch : $(InsertTargetBranch) 
250+             InsertionPayloadName : $(InsertPayloadName) 
251+             PackagePropsValues : $(InsertPackagePropsValues) 
252+             InsertionDescription : $(InsertDescription) 
253+             ComponentJsonValues : $(InsertJsonValues) 
254+             DefaultConfigValues : $(InsertConfigValues) 
255+             InsertionReviewers : MSBuild,VS ProTools 
256+             CustomScriptExecutionCommand : $(InsertCustomScriptExecutionCommand) 
257+             AutoCompletePR : true 
258+             AutoCompleteMergeStrategy : Squash 
259+             InsertionBuildPolicy : Request Perf DDRITs 
0 commit comments