diff --git a/.vsts-ci/linux.yml b/.vsts-ci/linux.yml index eb38e2ca73b..4d1131c9968 100644 --- a/.vsts-ci/linux.yml +++ b/.vsts-ci/linux.yml @@ -14,9 +14,14 @@ phases: - phase: Linux_CI queue: - name: Hosted Linux Preview + name: Hosted Ubuntu 1604 steps: - - powershell: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhss"))" + - powershell: | + Get-ChildItem -Path env: + displayName: Capture environment + condition: succeededOrFailed() + + - powershell: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhmmss"))" displayName: Set Build Name for Non-PR condition: ne(variables['Build.Reason'], 'PullRequest') @@ -33,8 +38,8 @@ phases: condition: succeededOrFailed() - powershell: | - apt-get update - apt-get install -y --no-install-recommends less + sudo apt-get update + sudo apt-get install -y --no-install-recommends less displayName: Install less condition: succeededOrFailed() @@ -65,14 +70,5 @@ phases: Write-Host "##vso[artifact.upload containerfolder=artifacts;artifactname=artifacts]$_" } displayName: Publish Artifacts - condition: succeededOrFailed() - continueOnError: true - - # Uploads any Test results as an artifact - - powershell: | - Get-ChildItem -Path Test*.xml, *XUnitTestResults.xml -Recurse | Select-Object -ExpandProperty FullName | ForEach-Object { - Write-Host "##vso[artifact.upload containerfolder=testResults;artifactname=testResults]$_" - } - displayName: Publish Test Results condition: ne(variables['Build.Reason'], 'PullRequest') continueOnError: true diff --git a/.vsts-ci/mac.yml b/.vsts-ci/mac.yml index 39a923233ff..55212e9d868 100644 --- a/.vsts-ci/mac.yml +++ b/.vsts-ci/mac.yml @@ -14,9 +14,14 @@ phases: - phase: macOS_CI queue: - name: Hosted macOS Preview + name: Hosted macOS steps: - - powershell: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhss"))" + - powershell: | + Get-ChildItem -Path env: + displayName: Capture environment + condition: succeededOrFailed() + + - powershell: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhmmss"))" displayName: Set Build Name for Non-PR condition: ne(variables['Build.Reason'], 'PullRequest') diff --git a/.vsts-ci/windows.yml b/.vsts-ci/windows.yml index f3541593a3d..80da3a87437 100644 --- a/.vsts-ci/windows.yml +++ b/.vsts-ci/windows.yml @@ -20,7 +20,12 @@ resources: clean: true steps: - - powershell: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhss"))" + - powershell: | + Get-ChildItem -Path env: + displayName: Capture environment + condition: succeededOrFailed() + + - powershell: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhmmss"))" displayName: Set Build Name for Non-PR condition: ne(variables['Build.Reason'], 'PullRequest') diff --git a/build.psm1 b/build.psm1 index 33e75e5063f..41e3d94676d 100644 --- a/build.psm1 +++ b/build.psm1 @@ -1825,7 +1825,7 @@ function Start-PSBootstrap { # We cannot guess if the user wants to run gem install as root on linux and windows, # but macOs usually requires sudo $gemsudo = '' - if($Environment.IsMacOS) { + if($Environment.IsMacOS -or $env:TF_BUILD) { $gemsudo = $sudo } Start-NativeExecution ([ScriptBlock]::Create("$gemsudo gem install fpm -v 1.10.0")) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs index c4a5e53747f..e067593f830 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs @@ -160,6 +160,18 @@ internal void ExecuteCommandAsync(string command, out Exception exceptionThrown, ExecuteCommandAsyncHelper(tempPipeline, out exceptionThrown, options); } + /// + /// Executes a pipeline in the console when we are running asnyc. + /// + /// + /// The pipeline to execute. + /// + /// + /// Any exception thrown trying to run the pipeline. + /// + /// + /// The options to use to execute the pipeline. + /// internal void ExecuteCommandAsyncHelper(Pipeline tempPipeline, out Exception exceptionThrown, ExecutionOptions options) { Dbg.Assert(!_isPromptFunctionExecutor, "should not async invoke the prompt"); @@ -192,7 +204,14 @@ internal void ExecuteCommandAsyncHelper(Pipeline tempPipeline, out Exception exc tempPipeline.Output.DataReady += new EventHandler(OutputObjectStreamHandler); tempPipeline.Error.DataReady += new EventHandler(ErrorObjectStreamHandler); - PipelineFinishedWaitHandle waiterThereIsAFlyInMySoup = new PipelineFinishedWaitHandle(tempPipeline); + PipelineFinishedWaitHandle pipelineWaiter = new PipelineFinishedWaitHandle(tempPipeline); + + // close the input pipeline so the command will do something + // if we are not reading input + if ((options & Executor.ExecutionOptions.ReadInputObjects) == 0) + { + tempPipeline.Input.Close(); + } tempPipeline.InvokeAsync(); if ((options & ExecutionOptions.ReadInputObjects) > 0 && Console.IsInputRedirected) @@ -224,7 +243,7 @@ internal void ExecuteCommandAsyncHelper(Pipeline tempPipeline, out Exception exc } tempPipeline.Input.Close(); - waiterThereIsAFlyInMySoup.Wait(); + pipelineWaiter.Wait(); //report error if pipeline failed if (tempPipeline.PipelineStateInfo.State == PipelineState.Failed && tempPipeline.PipelineStateInfo.Reason != null) diff --git a/test/powershell/Host/ConsoleHost.Tests.ps1 b/test/powershell/Host/ConsoleHost.Tests.ps1 index b6f3e35a696..7120283af15 100644 --- a/test/powershell/Host/ConsoleHost.Tests.ps1 +++ b/test/powershell/Host/ConsoleHost.Tests.ps1 @@ -548,7 +548,7 @@ foo @{ value = "~\$folderName"; expectedPath = $((Get-Item ~\$folderName).FullName) } ) { param($value, $expectedPath) - $output = & $powershell -WorkingDirectory "$value" -Command "`$pwd.Path" + $output = & $powershell -NoProfile -WorkingDirectory "$value" -Command '(Get-Location).Path' $output | Should -BeExactly $expectedPath } @@ -558,7 +558,7 @@ foo @{ parameter = '-wo' } ) { param($parameter) - $output = & $powershell $parameter ~ -Command "`$pwd.Path" + $output = & $powershell -NoProfile $parameter ~ -Command "`$pwd.Path" $output | Should -BeExactly $((Get-Item ~).FullName) } diff --git a/tools/travis.ps1 b/tools/travis.ps1 index 04b65bc0933..217377ca55e 100644 --- a/tools/travis.ps1 +++ b/tools/travis.ps1 @@ -154,12 +154,35 @@ function Set-DailyBuildBadge # One of push, pull_request, api, cron. $isPR = $env:TRAVIS_EVENT_TYPE -eq 'pull_request' +$commitMessage = [string]::Empty + # For PRs, Travis-ci strips out [ and ] so read the message directly from git -if($env:TRAVIS_EVENT_TYPE -eq 'pull_request') +if($env:TRAVIS_EVENT_TYPE -eq 'pull_request' -or $env:BUILD_REASON) { - # If the current job is a pull request, the env variable 'TRAVIS_PULL_REQUEST_SHA' contains - # the commit SHA of the HEAD commit of the PR. - $commitMessage = git log --format=%B -n 1 $env:TRAVIS_PULL_REQUEST_SHA + $commitId = $null + if ($env:TRAVIS_EVENT_TYPE) + { + # We are in Travis-CI + $commitId = $env:TRAVIS_PULL_REQUEST_SHA + + # If the current job is a pull request, the env variable 'TRAVIS_PULL_REQUEST_SHA' contains + # the commit SHA of the HEAD commit of the PR. + $commitMessage = git log --format=%B -n 1 $commitId + Write-Log -message "commitMessage: $commitMessage" + } + elseif($env:TF_BUILD) + { + if($env:BUILD_SOURCEVERSIONMESSAGE -match 'Merge\s*([0-9A-F]*)') + { + # We are in VSTS and have a commit ID in the Source Version Message + $commitId = $Matches[1] + $commitMessage = git log --format=%B -n 1 $commitId + } + else + { + Write-Log "Unknown BUILD_SOURCEVERSIONMESSAGE format '$env:BUILD_SOURCEVERSIONMESSAGE'" -Verbose + } + } } else { @@ -167,17 +190,26 @@ else } # Run a full build if the build was trigger via cron, api or the commit message contains `[Feature]` -$hasFeatureTag = $commitMessage -match '\[feature\]' -$hasPackageTag = $commitMessage -match '\[package\]' +# or the environment variable `FORCE_FEATURE` equals `True` +$hasFeatureTag = $commitMessage -match '\[feature\]' -or $env:FORCE_FEATURE -eq 'True' + +# Run a packaging if the commit message contains `[Package]` +# or the environment variable `FORCE_PACKAGE` equals `True` +$hasPackageTag = $commitMessage -match '\[package\]' -or $env:FORCE_PACKAGE -eq 'True' $createPackages = -not $isPr -or $hasPackageTag $hasRunFailingTestTag = $commitMessage -match '\[includeFailingTest\]' -$isDailyBuild = $env:TRAVIS_EVENT_TYPE -eq 'cron' -or $env:TRAVIS_EVENT_TYPE -eq 'api' +$isDailyBuild = $env:TRAVIS_EVENT_TYPE -eq 'cron' -or $env:TRAVIS_EVENT_TYPE -eq 'api' -or $env:BUILD_REASON -eq 'Schedule' # only update the build badge for the cron job -$cronBuild = $env:TRAVIS_EVENT_TYPE -eq 'cron' +$cronBuild = $env:TRAVIS_EVENT_TYPE -eq 'cron' -or $env:BUILD_REASON -eq 'Schedule' $isFullBuild = $isDailyBuild -or $hasFeatureTag if($Stage -eq 'Bootstrap') { + if($cronBuild -and $env:TF_BUILD) + { + Write-Host "##vso[build.updatebuildnumber]Daily-$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhmmss"))" + } + Write-Host -Foreground Green "Executing travis.ps1 -BootStrap `$isPR='$isPr' - $commitMessage" # Make sure we have all the tags Sync-PSTags -AddRemoteIfMissing