Skip to content

Instantly share code, notes, and snippets.

@jessehouwing
Created September 28, 2023 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessehouwing/4684f372300016d76e079d926fa6385c to your computer and use it in GitHub Desktop.
Save jessehouwing/4684f372300016d76e079d926fa6385c to your computer and use it in GitHub Desktop.
Performance Improvements
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- main
pool:
vmImage: windows-latest
variables:
"system.debug": true
stages:
- stage: 'Cache'
displayName: 'Cache'
jobs:
- job: 'Cache'
displayName: 'Cache'
steps:
- checkout: none
- script: |
c:
cd %USERPROFILE%
md .azure
cd .azure
net stop StorSvc
net stop wuauserv
- script: |
az config get
az devops configure --list
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
- pwsh: |
echo "dummy" | az devops login | out-null
az devops logout | out-null
displayName: "Do dummy login to install keyring"
- task: PublishPipelineArtifact@1
inputs:
targetPath: 'C:\Users\VssAdministrator\.azure'
artifact: '.azure'
publishLocation: 'pipeline'
- task: PublishPipelineArtifact@1
inputs:
targetPath: 'C:\Program Files\Common Files\AzureCliExtensionDirectory'
artifact: 'AzureCliExtensionDirectory'
publishLocation: 'pipeline'
- task: Cache@2
inputs:
key: '".az-devops"'
path: 'C:\Users\VssAdministrator\.azure-devops'
condition: true
- job: 'Run'
displayName: 'Run'
dependsOn: 'Cache'
strategy:
matrix:
"cache-az-on":
cache: "true"
command: "az config get"
"cache-az-off":
cache: "false"
command: "az config get"
"cache-devops-on":
cache: "true"
command: "az devops configure --list"
"cache-devips-off":
cache: "false"
command: "az devops configure --list"
steps:
- checkout: none
- pwsh: |
$services = @("WaasMedicSvc", "StorSvc", "wuauserv")
$services | %{
$action = "''/30000/''/30000/''/30000"
$output = sc.exe failure $_ actions=$action reset=4000
stop-service $_ -force
if ($_ -ne "WaasMedicSvc")
{
Set-Service -StartupType Disabled $_
}
if ((get-service $_).Status -ne "Stopped")
{
$id = Get-CimInstance -Class Win32_Service -Filter "Name LIKE '$_'" |
Select-Object -ExpandProperty ProcessId
$process = Get-Process -Id $id
$process.Kill()
}
}
$services | %{
write-host $_ $((get-service $_).Status)
}
- script: |
c:
cd %USERPROFILE%
md .azure
cd .azure
displayName: "Create empty .azure directory"
- script:
rd /s /q "C:\Program Files\Common Files\AzureCliExtensionDirectory"
displayName: "Clear AzureCliExtensionDirectory"
condition: eq(variables.cache, true )
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: '.azure'
targetPath: 'C:\Users\VssAdministrator\.azure'
displayName: "Restore .azure directory"
condition: eq(variables.cache, true )
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: 'AzureCliExtensionDirectory'
targetPath: 'C:\Program Files\Common Files\AzureCliExtensionDirectory'
displayName: "Restore azure cli extensions directory"
condition: eq(variables.cache, true )
- task: Cache@2
inputs:
key: '".az-devops"'
path: 'C:\Users\VssAdministrator\.azure-devops'
displayName: "Restore .azure-devops"
condition: eq(variables.cache, true )
- pwsh: |
(dir C:\Users\VssAdministrator\.azure-devops\python-sdk\cache\*.json) | %{$_.LastWriteTime = Get-Date}
displayName: "Reset last modified on .azure-deops/cache"
condition: eq(variables.cache, true )
- pwsh: |
$output = Invoke-Expression -Command "& $(command) --debug *>&1"
if ($output -like "*Modules found from index for*")
{
write-output "$(command) OK"
}
else
{
write-output "$(command) FAILED"
}
displayName: "Run $(command)."
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
- pwsh: |
$services = @("StorSvc", "wuauserv")
$services | %{
$status = (get-service $_).Status
if ($status -ne "Stopped")
{
write-error "$_ $status"
exit 1
}
}
displayName: "Fail if windows update or storage service is running."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment