Skip to content

Instantly share code, notes, and snippets.

Avatar

Richard Fennell rfennell

View GitHub Profile
@rfennell
rfennell / Move-GitTag.ps1
Created Jul 8, 2021
Move a Git tag to the most recent commit
View Move-GitTag.ps1
param
(
$tagname,
$trunk = 'main'
)
& git push origin :refs/tags/$tagname
& git tag -fa $tagname -m "Current $tagname release"
& git push origin $trunk --tags
@rfennell
rfennell / Get-AzureDevOpsEnvApprovel.ps1
Last active May 22, 2021
A code fragment that can be used in an Azure DevOps PowerShell task to find the approver of the current stage of a multi stage YAML pipeline
View Get-AzureDevOpsEnvApprovel.ps1
try {
# this block is in its own try/catch as it uses undocumented API calls, so will fail safe
# we need to stage ID which is only available via a REST call
$uri = "$(System.CollectionUri)/$(System.TeamProject)/_apis/build/builds/$(Build.BuildID)/timeline?api-version=6.0"
$response = Get-WebClient.DownloadString($uri) | ConvertFrom-Json
$stage = $response.records | where-object -property name -eq "$(System.StageName)"
# now we can get the approval, we have to use a new webclient instance else you get a 400 Bad Request error
$uri = "$(System.CollectionUri)_apis/Contribution/HierarchyQuery/project/$(System.TeamProject)?api-version=6.1-preview.1"
$payload = "{`"contributionIds`":[`"ms.vss-build-web.checks-panel-data-provider`"],`"dataProviderContext`":{`"properties`":{`"buildId`":`"$(Build.BuildID)`",`"stageIds`":`"$($stage.id)`",`"checkListItemType`":1,`"sourcePage`":{`"url`":`"$(System.CollectionUri)/$(System.TeamProject)/_build/results?buildId=$(Build.BuildID)&view=results`",`"routeId`":`"ms.vss-bui
@rfennell
rfennell / Remove-DeletedGitBranches.ps1
Last active Mar 16, 2021
A PowerShell script to do a git fetch with a prune then also delete any local branches of the same name
View Remove-DeletedGitBranches.ps1
param
(
[Parameter()]
[Switch]
$Force
)
Write-Host "Getting list of branches"
$output = [string] (& git.exe branch 2>&1)
$mainbranch = "main"
@rfennell
rfennell / BuildAgent.ps1
Last active Jan 20, 2021
A Lability definition to create an Azure DevOps Agent
View BuildAgent.ps1
configuration BuildAgent {
param (
[ValidateNotNull()]
[System.Management.Automation.PSCredential]$Credential,
[string]$EnvPrefix,
[Int]$RetryCount = 100,
[Int]$RetryIntervalSec = 30
)
@rfennell
rfennell / Update-LabilityRegistration.ps1
Created Dec 20, 2019
Registers a VHD disk image with Lability
View Update-LabilityRegistration.ps1
param (
[parameter(Mandatory = $true, HelpMessage = "Name of the Lablity enviroment definition")]
$mediaid ,
[parameter(Mandatory = $true, HelpMessage = "UNC path the VHDs are stored on")]
$downloadPath
)
$metadataFiles = Get-ChildItem -Path $downloadPath -filter *.metadata
foreach ($file in $metadataFiles) {
@rfennell
rfennell / Create-LabilityEnvironment.ps1
Last active Jan 6, 2020
Creates a new Lability Environment for an Azure DevOps build agent
View Create-LabilityEnvironment.ps1
param
(
[parameter(Mandatory = $true, HelpMessage = "Admin user name for new VM")]
$AgentUser,
[parameter(Mandatory = $true, HelpMessage = "Admin passworduser name for new VM")]
$AgentPassword,
[parameter(Mandatory = $true, HelpMessage = "Azure DevOps PAT token")]
$pat,
[parameter(Mandatory = $true, HelpMessage = "URL of Azure DevOps instance t register agent on e.g. https://dev.aure.com/myinstance")]
@rfennell
rfennell / Remove-LabilityEnviroment.ps1
Last active Jan 6, 2020
Calculates the parameters and then removes a Lability environment
View Remove-LabilityEnviroment.ps1
param
(
[parameter(Mandatory = $true, HelpMessage = "Lability environment name")]
$environmentName ,
[parameter(Mandatory = $true, HelpMessage = "An idenfication leter)]
$prefix,
[parameter(Mandatory = $true, HelpMessage = "Used as an index for the prefix and to calculate the IP address ")]
$index,
)
@rfennell
rfennell / Unregister-Agent.ps1
Created Dec 20, 2019
Finds an Azure Build agent, takes it off line then removes it registration
View Unregister-Agent.ps1
param
(
[parameter(Mandatory = $true, HelpMessage = "Azure DevOps PAT token")]
$pat,
[parameter(Mandatory = $true, HelpMessage = "URL of Azure DevOps instance e.g. https://dev.aure.com/myinstance")]
$url,
[parameter(Mandatory = $true, HelpMessage = "Azure DevOps Agent Pool name")]
$pool ,
[parameter(Mandatory = $true, HelpMessage = "Based name for agent to search for e.g MyAgent as part of B1MyAgent-123")]
$agentBaseName ,
@rfennell
rfennell / Copy-UserCapablityToAgent.ps1
Created Dec 20, 2019
Poll for an Azure Build Agent to become available and when available copy the capabilities
View Copy-UserCapablityToAgent.ps1
param
(
[parameter(Mandatory = $true, HelpMessage = "Azure DevOps PAT token")]
$pat,
[parameter(Mandatory = $true, HelpMessage = "URL of Azure DevOps instance e.g. https://dev.aure.com/myinstance")]
$url,
[parameter(Mandatory = $true, HelpMessage = "Azure DevOps Agent Pool name")]
$pool ,
[parameter(Mandatory = $true, HelpMessage = "Based name for agent to search for e.g MyAgent as part of B1MyAgent-123")]
$agentBaseName ,
@rfennell
rfennell / Add-UserCapablitiesToAgent.ps1
Last active Dec 20, 2019
Poll for an Azure Build Agent to become available and when available then add capabilities
View Add-UserCapablitiesToAgent.ps1
param
(
[parameter(Mandatory = $true, HelpMessage = "Azure DevOps PAT token")]
$pat,
[parameter(Mandatory = $true, HelpMessage = "URL of Azure DevOps instance e.g. https://dev.aure.com/myinstance")]
$url,
[parameter(Mandatory = $true, HelpMessage = "Azure DevOps Agent Pool name")]
$pool ,
[parameter(Mandatory = $true, HelpMessage = "Based name for agent to search for e.g MyAgent as part of B1MyAgent-123")]
$agentBaseName ,