Define pipeline variables with ps1 scripts
This commit is contained in:
Родитель
77ca4d2c1c
Коммит
a364baccdb
|
@ -40,11 +40,6 @@ TestResult.xml
|
|||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# DNX
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
# This artifact captures all variables defined in the ..\variables folder.
|
||||
# It "snaps" the values of these variables where we can compute them during the build,
|
||||
# and otherwise captures the scripts to run later during an Azure Pipelines environment release.
|
||||
|
||||
$RepoRoot = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\..")
|
||||
$ArtifactBasePath = "$RepoRoot\obj\_artifacts"
|
||||
$VariablesArtifactPath = "$ArtifactBasePath\variables"
|
||||
if (-not (Test-Path $VariablesArtifactPath)) { New-Item -ItemType Directory -Path $VariablesArtifactPath | Out-Null }
|
||||
|
||||
# Copy variables, either by value if the value is calculable now, or by script
|
||||
Get-ChildItem -Path "$PSScriptRoot\..\variables" |% {
|
||||
$value = $null
|
||||
if (-not $_.BaseName.StartsWith('_')) { # Skip trying to interpret special scripts
|
||||
# First check the environment variables in case the variable was set in a queued build
|
||||
if (Test-Path env:$($_.BaseName)) {
|
||||
$value = Get-Content "env:$($_.BaseName)"
|
||||
}
|
||||
|
||||
# If that didn't give us anything, try executing the script right now from its original position
|
||||
if (-not $value) {
|
||||
$value = & $_.FullName
|
||||
}
|
||||
|
||||
if ($value) {
|
||||
# We got something, so wrap it with quotes so it's treated like a literal value.
|
||||
$value = "'$value'"
|
||||
}
|
||||
}
|
||||
|
||||
# If that didn't get us anything, just copy the script itself
|
||||
if (-not $value) {
|
||||
$value = Get-Content -Path $_.FullName
|
||||
}
|
||||
|
||||
Set-Content -Path "$VariablesArtifactPath\$($_.Name)" -Value $value
|
||||
}
|
||||
|
||||
@{
|
||||
"$VariablesArtifactPath" = (Get-ChildItem $VariablesArtifactPath -Recurse);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
# This script returns all the artifacts that should be collected after a build.
|
||||
#
|
||||
# Each powershell artifact is expressed as an object with these properties:
|
||||
# Source - the full path to the source file
|
||||
# ArtifactName - the name of the artifact to upload to
|
||||
# ContainerFolder - the relative path within the artifact in which the file should appear
|
||||
#
|
||||
# Each artifact aggregating .ps1 script should return a hashtable:
|
||||
# Key = path to the directory from which relative paths within the artifact should be calculated
|
||||
# Value = an array of paths (absolute or relative to the BaseDirectory) to files to include in the artifact.
|
||||
# FileInfo objects are also allowed.
|
||||
|
||||
$RepoRoot = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\..")
|
||||
$ArtifactStagingDirectory = "$RepoRoot\obj\artifacts\"
|
||||
|
||||
Function EnsureTrailingSlash($path) {
|
||||
if ($path.length -gt 0 -and $path[$path.length-1] -ne '\') {
|
||||
$path = $path + '\'
|
||||
}
|
||||
|
||||
$path
|
||||
}
|
||||
|
||||
Get-ChildItem "$PSScriptRoot\*.ps1" -Exclude "_*" -Recurse |% {
|
||||
$ArtifactName = $_.BaseName
|
||||
|
||||
(& $_).GetEnumerator() |% {
|
||||
$BaseDirectory = New-Object Uri ((EnsureTrailingSlash $_.Key), [UriKind]::Absolute)
|
||||
$_.Value |% {
|
||||
if ($_.GetType() -eq [IO.FileInfo] -or $_.GetType() -eq [IO.DirectoryInfo]) {
|
||||
$_ = $_.FullName
|
||||
}
|
||||
|
||||
$artifact = New-Object -TypeName PSObject
|
||||
Add-Member -InputObject $artifact -MemberType NoteProperty -Name ArtifactName -Value $ArtifactName
|
||||
|
||||
$SourceFullPath = New-Object Uri ($BaseDirectory, $_)
|
||||
Add-Member -InputObject $artifact -MemberType NoteProperty -Name Source -Value $SourceFullPath.LocalPath
|
||||
|
||||
$RelativePath = [Uri]::UnescapeDataString($BaseDirectory.MakeRelative($SourceFullPath))
|
||||
Add-Member -InputObject $artifact -MemberType NoteProperty -Name ContainerFolder -Value (Split-Path $RelativePath)
|
||||
|
||||
Write-Output $artifact
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
# This script translates all the artifacts described by _all.ps1
|
||||
# into commands that instruct VSTS to actually collect those artifacts.
|
||||
|
||||
$RepoRoot = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\..")
|
||||
if (!$env:BuildConfiguration) { throw "BuildConfiguration environment variable must be set." }
|
||||
if ($env:Build_ArtifactStagingDirectory) {
|
||||
$ArtifactStagingFolder = $env:Build_ArtifactStagingDirectory
|
||||
} else {
|
||||
$ArtifactStagingFolder = "$RepoRoot\obj\_artifacts"
|
||||
if (Test-Path $ArtifactStagingFolder) {
|
||||
Remove-Item $ArtifactStagingFolder -Recurse -Force
|
||||
}
|
||||
}
|
||||
|
||||
function mklink {
|
||||
cmd /c mklink $args
|
||||
}
|
||||
|
||||
# Stage all artifacts
|
||||
$Artifacts = & "$PSScriptRoot\_all.ps1"
|
||||
$Artifacts |% {
|
||||
$DestinationFolder = (Join-Path (Join-Path $ArtifactStagingFolder $_.ArtifactName) $_.ContainerFolder).TrimEnd('\')
|
||||
$Name = Split-Path $_.Source -Leaf
|
||||
|
||||
#Write-Host "$($_.Source) -> $($_.ArtifactName)\$($_.ContainerFolder)" -ForegroundColor Yellow
|
||||
|
||||
if (-not (Test-Path $DestinationFolder)) { New-Item -ItemType Directory -Path $DestinationFolder | Out-Null }
|
||||
if (Test-Path -PathType Leaf $_.Source) { # skip folders
|
||||
mklink "$DestinationFolder\$Name" $_.Source
|
||||
}
|
||||
}
|
||||
|
||||
$Artifacts |% { $_.ArtifactName } | Get-Unique |% {
|
||||
Write-Host "##vso[artifact.upload containerfolder=$_;artifactname=$_;]$ArtifactStagingFolder\$_"
|
||||
}
|
|
@ -33,7 +33,6 @@ steps:
|
|||
azure-pipelines\Convert-PDB.ps1 -DllPath $_ -OutputPath "$OutputDir\$($_.BaseName).pdb"
|
||||
}
|
||||
displayName: Converting portable PDBs to Windows PDBs
|
||||
condition: and(succeeded(), ne(variables['system.pullrequest.isfork'], true))
|
||||
|
||||
- task: CopyFiles@1
|
||||
inputs:
|
||||
|
@ -43,7 +42,6 @@ steps:
|
|||
StreamJsonRpc/$(BuildConfiguration)/**/symstore/StreamJsonRpc.pdb
|
||||
TargetFolder: $(Build.ArtifactStagingDirectory)/symbols
|
||||
displayName: Collecting symbols artifacts
|
||||
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
|
||||
|
||||
- task: PublishBuildArtifacts@1
|
||||
inputs:
|
||||
|
@ -51,7 +49,6 @@ steps:
|
|||
ArtifactName: symbols
|
||||
ArtifactType: Container
|
||||
displayName: Publish symbols as Azure DevOps artifacts
|
||||
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
|
||||
|
||||
- task: PublishSymbols@2
|
||||
inputs:
|
||||
|
|
|
@ -2,32 +2,15 @@ steps:
|
|||
- script: |
|
||||
dotnet tool install --tool-path .. nbgv
|
||||
..\nbgv cloud
|
||||
echo ##vso[task.setvariable variable=PATH]%Path%;$(Build.SourcesDirectory)
|
||||
workingDirectory: src
|
||||
displayName: Set build number
|
||||
condition: ne(variables['system.pullrequest.isfork'], true)
|
||||
|
||||
- task: PowerShell@2
|
||||
displayName: Set VSTS variables
|
||||
inputs:
|
||||
targetType: inline
|
||||
script: |
|
||||
if ($env:SignType -eq 'Real') {
|
||||
$feedGuid = '09d8d03c-1ac8-456e-9274-4d2364527d99'
|
||||
} else {
|
||||
$feedGuid = 'da484c78-f942-44ef-b197-99e2a1bef53c'
|
||||
}
|
||||
|
||||
Write-Host "##vso[task.setvariable variable=feedGuid]$feedGuid"
|
||||
|
||||
if ($env:ComputerName.StartsWith('factoryvm', [StringComparison]::OrdinalIgnoreCase)) {
|
||||
Write-Host "Running on hosted queue"
|
||||
Write-Host "##vso[task.setvariable variable=Hosted]true"
|
||||
}
|
||||
|
||||
if ($env:SYSTEM_COLLECTIONID -eq '011b8bdf-6d56-4f87-be0d-0092136884d9') {
|
||||
Write-Host "Running on official devdiv account: $env:System_TeamFoundationCollectionUri"
|
||||
} else {
|
||||
Write-Host "Running under OSS account: $env:System_TeamFoundationCollectionUri"
|
||||
}
|
||||
filePath: azure-pipelines\variables\_pipelines.ps1
|
||||
failOnStderr: true
|
||||
displayName: Set pipeline variables based on source
|
||||
|
||||
- ${{ if eq(variables['system.collectionId'], '011b8bdf-6d56-4f87-be0d-0092136884d9') }}:
|
||||
- template: azure-pipeline.microbuild.before.yml
|
||||
|
@ -81,7 +64,7 @@ steps:
|
|||
ArtifactName: projectAssetsJson
|
||||
ArtifactType: Container
|
||||
displayName: Publish projectAssetsJson artifacts
|
||||
condition: and(succeededOrFailed(), ne(variables['system.pullrequest.isfork'], true))
|
||||
condition: succeededOrFailed()
|
||||
|
||||
- task: PublishBuildArtifacts@1
|
||||
inputs:
|
||||
|
@ -89,16 +72,18 @@ steps:
|
|||
ArtifactName: build_logs
|
||||
ArtifactType: Container
|
||||
displayName: Publish build_logs artifacts
|
||||
condition: and(succeededOrFailed(), ne(variables['system.pullrequest.isfork'], true))
|
||||
condition: succeededOrFailed()
|
||||
|
||||
## The rest of these steps are for deployment and skipped for PR builds
|
||||
- task: PowerShell@2
|
||||
inputs:
|
||||
filePath: azure-pipelines\variables\_pipelines.ps1
|
||||
failOnStderr: true
|
||||
displayName: Update pipeline variables based on build outputs
|
||||
|
||||
#- task: PublishBuildArtifacts@1
|
||||
# inputs:
|
||||
# PathtoPublish: $(build.sourcesdirectory)/bin
|
||||
# ArtifactName: bin
|
||||
# ArtifactType: Container
|
||||
# condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'), ne(variables['system.pullrequest.isfork'], true))
|
||||
- task: PowerShell@2
|
||||
inputs:
|
||||
filePath: azure-pipelines\artifacts\_pipelines.ps1
|
||||
displayName: Publish artifacts
|
||||
|
||||
- task: VSTest@2
|
||||
displayName: Run tests on .NET Framework (with code coverage)
|
||||
|
@ -115,14 +100,12 @@ steps:
|
|||
- ${{ if eq(variables['system.collectionId'], '011b8bdf-6d56-4f87-be0d-0092136884d9') }}:
|
||||
- template: azure-pipeline.microbuild.after.yml
|
||||
|
||||
- task: CopyFiles@1
|
||||
inputs:
|
||||
Contents: |
|
||||
bin/**/$(BuildConfiguration)/**/StreamJsonRpc.*.nupkg
|
||||
TargetFolder: $(Build.ArtifactStagingDirectory)/deployables
|
||||
flattenFolders: true
|
||||
- task: PowerShell@2
|
||||
displayName: Collecting deployables
|
||||
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
|
||||
inputs:
|
||||
targetType: inline
|
||||
script: |
|
||||
Get-ChildItem bin\Packages\$(BuildConfiguration)\NuGet\*.nupkg -rec |% { copy $_ $(Build.ArtifactStagingDirectory)\deployables }
|
||||
|
||||
- task: PublishBuildArtifacts@1
|
||||
inputs:
|
||||
|
@ -130,4 +113,3 @@ steps:
|
|||
ArtifactName: deployables
|
||||
ArtifactType: Container
|
||||
displayName: Publish deployables artifacts
|
||||
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'), ne(variables['system.pullrequest.isfork'], true))
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
if ($env:ComputerName.StartsWith('factoryvm', [StringComparison]::OrdinalIgnoreCase)) {
|
||||
Write-Host "Running on hosted queue"
|
||||
Write-Output $true
|
||||
} else {
|
||||
Write-Output $false
|
||||
}
|
||||
|
||||
if ($env:SYSTEM_COLLECTIONID -eq '011b8bdf-6d56-4f87-be0d-0092136884d9') {
|
||||
Write-Host "Running on official devdiv account: $env:System_TeamFoundationCollectionUri"
|
||||
} elseif ($env:SYSTEM_COLLECTIONID) {
|
||||
Write-Host "Running under OSS account: $env:System_TeamFoundationCollectionUri"
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
$BinPath = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\..\bin\Packages\$env:BuildConfiguration")
|
||||
|
||||
$icv=@()
|
||||
if (Test-Path "$BinPath") {
|
||||
Get-ChildItem -Path "$BinPath\*.nupkg" -rec |% {
|
||||
if ($_.Name -match "^(.*)\.(\d+\.\d+\.\d+(?:-.*?)?)(?:\.symbols)?\.nupkg$") {
|
||||
$id = $Matches[1]
|
||||
$version = $Matches[2]
|
||||
$icv += "$id=$version"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Output ([string]::join(',',$icv))
|
|
@ -0,0 +1,3 @@
|
|||
# This is the default branch of the VS repo that we will use to insert into VS.
|
||||
# It may also be the value used by the IBCMergeBranch variable.
|
||||
'lab/d16.1stg'
|
|
@ -0,0 +1,3 @@
|
|||
[string]::join(',',(@{
|
||||
'StreamJsonRpcVersion' = & { (nbgv get-version --project "$PSScriptRoot\..\..\src\StreamJsonRpc" --format json | ConvertFrom-Json).AssemblyVersion };
|
||||
}.GetEnumerator() |% { "$($_.key)=$($_.value)" }))
|
|
@ -0,0 +1,5 @@
|
|||
if ($env:SignType) {
|
||||
$env:SignType
|
||||
} elseif ($env:SYSTEM_COLLECTIONID -eq '011b8bdf-6d56-4f87-be0d-0092136884d9') {
|
||||
'test'
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
'VS IDE'
|
|
@ -0,0 +1,10 @@
|
|||
# This script returns a hashtable of build variables that should be set
|
||||
# at the start of a build or release definition's execution.
|
||||
|
||||
$vars = @{}
|
||||
|
||||
Get-ChildItem "$PSScriptRoot\*.ps1" -Exclude "_*" |% {
|
||||
$vars[$_.BaseName] = & $_
|
||||
}
|
||||
|
||||
$vars
|
|
@ -0,0 +1,15 @@
|
|||
# This script translates the variables returned by the _all.ps1 script
|
||||
# into commands that instruct VSTS to actually set those variables for other VSTS tasks to consume.
|
||||
|
||||
# The build or release definition may have set these variables to override
|
||||
# what the build would do. So only set them if they have not already been set.
|
||||
|
||||
(& "$PSScriptRoot\_all.ps1").GetEnumerator() |% {
|
||||
if (Test-Path -Path "env:$($_.Key)") {
|
||||
Write-Host "Skipping setting $($_.Key) because variable is already set." -ForegroundColor Cyan
|
||||
} else {
|
||||
Write-Host "$($_.Key)=$($_.Value)" -ForegroundColor Yellow
|
||||
Write-Host "##vso[task.setvariable variable=$($_.Key);]$($_.Value)"
|
||||
Set-Item -Path "env:$($_.Key)" -Value $_.Value
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
if ($env:SignType -eq 'Real') {
|
||||
'09d8d03c-1ac8-456e-9274-4d2364527d99'
|
||||
} else {
|
||||
'da484c78-f942-44ef-b197-99e2a1bef53c'
|
||||
}
|
|
@ -1,9 +1,15 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)..\obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
|
||||
<BaseOutputPath Condition=" '$(BaseOutputPath)' == '' ">$(MSBuildThisFileDirectory)..\bin\$(MSBuildProjectName)\</BaseOutputPath>
|
||||
|
||||
<RepoRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\'))</RepoRoot>
|
||||
<RepoBinPath>$(RepoRoot)bin\</RepoBinPath>
|
||||
<RepoObjPath>$(RepoRoot)obj\</RepoObjPath>
|
||||
<BaseIntermediateOutputPath>$(RepoObjPath)\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
|
||||
<BaseOutputPath Condition=" '$(BaseOutputPath)' == '' ">$(RepoBinPath)\$(MSBuildProjectName)\</BaseOutputPath>
|
||||
<PackageOutputPath>$(RepoBinPath)Packages\$(Configuration)\NuGet\</PackageOutputPath>
|
||||
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
<CodeAnalysisRuleSet>StreamJsonRpc.ruleset</CodeAnalysisRuleSet>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DefineConstants Condition=" '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'net46' or '$(TargetFramework)' == 'netstandard2.0' ">$(DefineConstants);WEBSOCKETS</DefineConstants>
|
||||
<DefineConstants Condition=" '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'net46' or '$(TargetFramework)' == 'netstandard2.0' ">$(DefineConstants);SERIALIZABLE_EXCEPTIONS</DefineConstants>
|
||||
|
|
Загрузка…
Ссылка в новой задаче