Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4f25c8f
Wait for package manager not to be locked
TravisEz13 Sep 18, 2018
eab772c
[Feature] Add daily and feature tag support
TravisEz13 Aug 29, 2018
bc5164d
switch windows just to always run feature tests
TravisEz13 Aug 29, 2018
e8d4b57
Use helper function to set build variable
TravisEz13 Aug 30, 2018
c9df1c5
Update release tag generation
TravisEz13 Aug 30, 2018
1ea009a
[Feature] update windows VSTS to support [feature] tag
TravisEz13 Sep 7, 2018
04df8a0
Add logging about why we are exiting unelevated logging loop
TravisEz13 Aug 31, 2018
c62d245
complete comment
TravisEz13 Sep 17, 2018
eab1c87
fix build issues
TravisEz13 Sep 17, 2018
2745401
fix typo in creating releasetag
TravisEz13 Sep 17, 2018
0b5dd72
fix preReleaseVersion
TravisEz13 Sep 18, 2018
0fdffd3
set permission on output file
TravisEz13 Sep 18, 2018
0b64667
load environment in new process
TravisEz13 Sep 18, 2018
1719c45
use arguments instead of argument list
TravisEz13 Sep 18, 2018
40c90fc
fix duplicate key issue
TravisEz13 Sep 18, 2018
86f0854
remove TMPDIR
TravisEz13 Sep 18, 2018
ea77a77
fix typo
TravisEz13 Sep 19, 2018
76436fc
use NetCred to parse username
TravisEz13 Sep 19, 2018
6a93fb8
give non-admin user permissions to TEMP
TravisEz13 Sep 19, 2018
5f971df
set correct temp path
TravisEz13 Sep 19, 2018
8c40acf
create temp and appdata folders for non-admin
TravisEz13 Sep 19, 2018
8803e04
Capture test stack trace
TravisEz13 Sep 19, 2018
f9d5b75
fix typo
TravisEz13 Sep 19, 2018
b74cd12
add instrumentation to debug
TravisEz13 Sep 19, 2018
a23645a
don't return the icacls results
TravisEz13 Sep 19, 2018
3a2d20b
inherit permissions
TravisEz13 Sep 19, 2018
f6bfd8e
create a userprofile folder for non-admi
TravisEz13 Sep 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions .vsts-ci/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,31 @@ phases:
queue:
name: Hosted Ubuntu 1604
steps:
- powershell: |
Get-Process
displayName: Capture Processes
condition: succeededOrFailed()

- powershell: |
Get-ChildItem -Path env:
displayName: Capture environment
condition: succeededOrFailed()

- powershell: |
# sometimes the file is locked and we must wait or things will fail
$filePath = '/var/lib/dpkg/lock'
$lockList = sudo lsof '/var/lib/dpkg/lock'
while($lockList)
{
Write-Verbose "waiting..." -verbose
Write-Verbose ($lockList -join "`n") -verbose
Start-Sleep -Second 30
$lockList = sudo lsof $filePath
}
exit 0
displayName: Wait for /var/lib/dpkg/lock
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')
Expand All @@ -35,12 +55,6 @@ phases:
displayName: SubModule Init
condition: succeededOrFailed()

- powershell: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends less
displayName: Install less
condition: succeededOrFailed()

- powershell: |
tools/travis.ps1 -Stage Bootstrap
displayName: Bootstrap
Expand Down
91 changes: 88 additions & 3 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,15 @@ function Start-PSPester {
# we need to do few checks and if user didn't provide $ExcludeTag explicitly, we should alternate the default
if ($Unelevate)
{
$Script:psNonAdminCred = $null
$nonAdminCredsPath = "$env:TEMP\PsNonAdminCred.xml"

# AppVeyor doesn't work well with a non-admin user
if ((Test-Path -Path $nonAdminCredsPath) -and !$env:AppVeyor)
{
try { $Script:psNonAdminCred = Import-Clixml -Path $nonAdminCredsPath } catch { }
}

if (-not $Environment.IsWindows)
{
throw '-Unelevate is currently not supported on non-Windows platforms'
Expand Down Expand Up @@ -1150,7 +1159,17 @@ function Start-PSPester {

if ($Unelevate)
{
$outputBufferFilePath = [System.IO.Path]::GetTempFileName()
if($Script:psNonAdminCred)
{
$outputBufferFolder = New-SubFolderWithPermissions -Path $env:SystemDrive -ChildPath ([System.IO.Path]::GetRandomFileName())
$outputBufferFilePath = Join-Path -Path $outputBufferFolder -ChildPath ([System.IO.Path]::GetRandomFileName())
$null = New-Item -ItemType File -Path $outputBufferFilePath
$null = icacls $outputBufferFilePath /grant Everyone:F
}
else
{
$outputBufferFilePath = [System.IO.Path]::GetTempFileName()
}
}

$command += "Invoke-Pester "
Expand Down Expand Up @@ -1286,6 +1305,7 @@ function Start-PSPester {
}
if ($lines | Where-Object { $_ -eq '__UNELEVATED_TESTS_THE_END__'})
{
Write-Log "Got end of unelevated tests"
break
}

Expand Down Expand Up @@ -1346,7 +1366,7 @@ function Start-PSPester {
$env:POWERSHELL_TELEMETRY_OPTOUT = $originalTelemetry
if ($Unelevate)
{
Remove-Item $outputBufferFilePath
Remove-Item $outputBufferFilePath -ErrorAction SilentlyContinue
}
}

Expand Down Expand Up @@ -1399,7 +1419,72 @@ function script:Start-UnelevatedProcess
throw "Start-UnelevatedProcess is currently not supported on non-Windows platforms"
}

runas.exe /trustlevel:0x20000 "$process $arguments"
# the current consumer of this function does not depend on
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems not complete.

# this function waiting on the process to complete
if ($Script:psNonAdminCred)
{
Write-Log "Running with non-admin user..."
$psi = [System.Diagnostics.ProcessStartInfo]::new($process)
$psi.Arguments = "$arguments"
$netCred = $Script:psNonAdminCred.GetNetworkCredential()
$psi.Password = $Script:psNonAdminCred.Password
$psi.UserName = $netCred.UserName
$psi.Domain = $netCred.Domain
# Shell execute must be false for both the password and environment
$psi.UseShellExecute = $false
$psi.WorkingDirectory = (Get-Location).ProviderPath
# Set variables we want to carry over to the new process
Get-ChildItem env:SYSTEM_*, env:BUILD_*, env:TF_*, env:AGENT_* | ForEach-Object {
$psi.EnvironmentVariables[$_.Name]=$_.Value
}

# Setup directories non-admin user can use
$nonAdminRoot = New-SubFolderWithPermissions -Path $env:TEMP -ChildPath ([System.IO.Path]::GetRandomFileName())
$nonAdminProfile = New-SubFolderWithPermissions -Path $nonAdminRoot -ChildPath 'profile'
$nonAdminTemp = New-SubFolderWithPermissions -Path $nonAdminRoot -ChildPath 'temp'
$nonAdminAppData = New-SubFolderWithPermissions -Path $nonAdminRoot -ChildPath 'AppData'
$nonAdminAppDataLocal = New-SubFolderWithPermissions -Path $nonAdminAppData -ChildPath 'Local'
$nonAdminAppDataRemote = New-SubFolderWithPermissions -Path $nonAdminAppData -ChildPath 'Remote'
$psi.EnvironmentVariables['TEMP']=$nonAdminTemp
$psi.EnvironmentVariables['LOCALAPPDATA']=$nonAdminAppDataLocal
$psi.EnvironmentVariables['APPDATA']=$nonAdminAppDataRemote
$psi.EnvironmentVariables['USERPROFILE']=$nonAdminProfile

[System.Diagnostics.Process]::Start($psi)

#Start-Process -FilePath $process -ArgumentList $arguments -Credential $Script:psNonAdminCred
}
else
{
Write-Log "Using runas to launch unelevated..."
runas.exe /trustlevel:0x20000 "$process $arguments"
}
}

function New-SubFolderWithPermissions
{
param(
[string]
$Path,
[string]
$ChildPath,
[string]
$Permissions = 'Everyone:F'
)

Write-Verbose "New-SubFolderWithPermissions - Path: '$Path', ChildPath: '$ChildPath'" -Verbose
$newFolderPath = Join-Path -Path $Path -ChildPath $ChildPath

Write-Verbose "New-SubFolderWithPermissions - newFolderPath: '$newFolderPath'" -Verbose
$null = New-Item -ItemType Directory -Path $newFolderPath

Write-Verbose "New-SubFolderWithPermissions - granting permssions: '$Permissions'" -Verbose
$acl = Get-Acl -Path $newFolderPath
$accessrule = New-Object System.Security.AccessControl.FileSystemAccessRule ('Everyone', 'FullControl', 'ContainerInherit, ObjectInherit', 'InheritOnly', 'Allow')
$acl.SetAccessRule($accessrule)
Set-Acl -Path $newFolderPath -AclObject $acl
#$null = icacls $newFolderPath /grant $Permissions
return $newFolderPath
}

function Show-PSPesterError
Expand Down
Loading