You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
7.5 KiB

  1. # Arcade Minimal CI Sample
  2. [![Build status](https://dnceng.visualstudio.com/9ee6d478-d288-47f7-aacc-f6e6d082ae6d/_apis/build/status/116?branchName=master)](https://dnceng.visualstudio.com/public/_build/latest?definitionId=116&branch=master)
  3. This repository serves as an example of how to link GitHub repositories to VSTS for CI and PR builds.
  4. ## Before You Start
  5. You'll want to start by following the [VSTS Onboarding](https://github.com/dotnet/arcade/blob/master/Documentation/VSTS/VSTSOnboarding.md) instructions, which provide a thorough, step-by-step list of instructions for creating VSTS CI builds for GitHub repos. From there, you'll find the [VSTS YAML documentation](https://github.com/Microsoft/vsts-agent/blob/master/docs/preview/yamlgettingstarted.md), which details the creation of VSTS CI YAML files.
  6. The purpose of this repository is to provide a jumping off point with an example YAML CI file that already has the basic architecture you'll want for your builds. All examples below are taken from this repository's [.vsts-ci.yml](.vsts-ci.yml).
  7. ## Set build triggers in your YAML
  8. Documentation on setting CI triggers in YAML can be found [here](https://github.com/Microsoft/vsts-agent/blob/master/docs/preview/yamlgettingstarted-ci.md). The syntax for pull request triggers is identical, and will trigger whenever a PR is created merging into your specified branches.
  9. **Note: YAML-based PR triggers are a feature currently being rolled out by VSTS. Until they are completed, you must override the YAML PR trigger settings from the build definition GUI on VSTS.**
  10. ```yaml
  11. trigger:
  12. - master
  13. # Commenting out until VSTS supports YAML PR triggers
  14. # pr:
  15. # - master
  16. ```
  17. ## Base your builds on Arcade for ease of use
  18. Arcade is designed to make many of the more complex tasks (such as sending telemetry) simple to do out of the box. It is therefore recommended that all builds base themselves on Arcade's `base.yml` template. Today, this can be done by copying the `eng/common` folder from Arcade into a local `eng/common` folder. In the near future, Engineering services will provide the capability to auto-update this folder via Maestro so that you don't need to manually take updates to common Arcade scripts.
  19. ```yaml
  20. phases:
  21. - template: /eng/common/templates/phases/base.yml
  22. parameters:
  23. ...
  24. ```
  25. ## Use the Arcade SDK for an easier build process
  26. To quickstart your builds, you can use the Arcade SDK's build scripts. Clone the `eng/*` folder from this repository and copy [`Directory.Build.props`](Directory.Build.props), [`Directory.Build.targets`](Directory.Build.targets), [`global.json`](global.json), and [`NuGet.Config`](NuGet.Config) into your root directory. To use the build scripts, simply use a `script` task to run `eng\common\cibuild.cmd` on Windows or `eng/common/cibuild.sh` on a Unix-based OS.
  27. ```yaml
  28. # for Windows
  29. steps:
  30. - script: eng\common\cibuild.cmd
  31. -configuration $(_BuildConfig)
  32. -prepareMachine
  33. # for Unix-based
  34. steps:
  35. - script: eng/common/cibuild.sh
  36. --configuration $(_BuildConfig)
  37. --prepareMachine
  38. ```
  39. Note: for the Unix-based scripts to work, make sure you clone rather than copy/paste while on Windows—copying and pasting will remove the `x` chmod parameter from the Unix scripts, which will build breaks when attempting to run them.
  40. ## Use matrices to quickly create phases for different build configurations
  41. VSTS supports using a **matrix** in a phase definition to quickly create several different phases on the same queue with slightly different build configurations. This is the recommended way to quickly add debug and release configuration builds.
  42. ```yaml
  43. - phase: Windows
  44. queue:
  45. name: Helix
  46. parallel: 99
  47. matrix:
  48. debug_configuration:
  49. _BuildConfig: Debug
  50. release_configuration:
  51. _BuildConfig: Release
  52. ```
  53. The variable defined in this matrix (in this case, `_BuildConfig`) can later be referenced in your build steps:
  54. ```yaml
  55. - task: DotNetCoreCLI@2
  56. inputs:
  57. command: 'build'
  58. projects: '**/*.csproj'
  59. arguments: '--configuration $(_BuildConfig)'
  60. ```
  61. ## Run both CI and PR builds out of the same file
  62. While this sample repository has no need to do so, there are many scenarios in which you may want to differentiate between different build triggers. The current recommendation is that all repositories have a single `.vsts-ci.yml` file which defines all of their builds (CI, PR, and internal). To do this, use YAML `{{ if }}` directives and the VSTS built-in `Build.Reason` variable.
  63. ```yaml
  64. - ${{ if notIn(variables['Build.Reason'], 'PullRequest') }}:
  65. - task: DotNetCoreCLI@2
  66. inputs:
  67. command: 'publish'
  68. projects: 'HelloWorld/HelloWorld.csproj'
  69. publishWebProjects: false
  70. arguments: '--configuration $(_BuildConfig) --output $(build.ArtifactStagingDirectory) --framework $(targetFramework)'
  71. displayName: dotnet publish
  72. ```
  73. ## Enabling telmetry
  74. [Arcade](#base-your-builds-on-arcade-for-ease-of-use) provides the ability to send telemetry. To enable telemetry you must...
  75. 1. Set `enableTelemetry` to `true`
  76. 2. Define the `_HelixType`, `_HelixSource`, and `_HelixBuildConfig` variables
  77. - `_HelixType` - This is a string that defines the type of run you are currently performing. Note that a trailing slash is required. e.g. test/functional/cli/, build/product/
  78. - `_HelixSource` - This defines information about the run in a specific format Type/repo/branch/. Note that a trailing slash is required. e.g. pr/corefx/master/, official/coreclr/master/
  79. - `_HelixBuildConfig` - The build configuration for your current build ie, Release, Debug, etc
  80. 3. For official builds, add an "AzureKeyVault" task reference to `HelixProdKV`
  81. ```YAML
  82. phases:
  83. - template: /eng/common/templates/phases/base.yml@arcade
  84. parameters:
  85. agentOs: Windows_NT
  86. name: Windows_NT
  87. enableTelemetry: true
  88. variables:
  89. _HelixType: build/product
  90. _HelixBuildConfig: $(_BuildConfig)
  91. ${{ if notIn(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'PullRequest') }}:
  92. _HelixSource: official/dotnet/arcade-minimalci-sample/$(Build.SourceBranch)
  93. ${{ if in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'PullRequest') }}:
  94. _HelixSource: pr/dotnet/arcade-minimalci-sample/$(Build.SourceBranch)
  95. steps:
  96. - ${{ if notIn(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'PullRequest') }}:
  97. - task: AzureKeyVault@1
  98. inputs:
  99. azureSubscription: 'HelixProd_KeyVault'
  100. KeyVaultName: HelixProdKV
  101. SecretsFilter: 'HelixApiAccessToken'
  102. # conditions - https://docs.microsoft.com/en-us/vsts/pipelines/process/conditions?view=vsts
  103. condition: always()
  104. ```
  105. ## Using the SignToolTask
  106. Arcade provides an optimized way to sign files using MicroBuild, it is wrapped in a custom MSBuild task called [SignToolTask](https://github.com/dotnet/arcade/blob/master/src/Microsoft.DotNet.SignTool/src/SignToolTask.cs).
  107. The Arcade SDK will automatically [find package](https://github.com/dotnet/arcade/blob/ae38bbbc25d03e1deb49b15ce88e2dd4c683e116/src/Microsoft.DotNet.Arcade.Sdk/tools/Sign.proj) files and forward them to be signed using SignToolTask. Therefore, if the only files that you care to sign are covered by the linked line above you don't have to do anything else. If not, you have options. You can specify explicit files to be signed / excluded from signing or changing the certificate / strong name to be used. For a detailed guide see the [SignTool package documentation](https://github.com/dotnet/arcade/blob/master/src/Microsoft.DotNet.SignTool/README.md).