pipeline file changes

This commit is contained in:
Brett Hewitson 2022-12-29 11:12:15 +10:00
parent 6d1da1270f
commit 942fdb66d3
2 changed files with 183 additions and 143 deletions

View file

@ -40,167 +40,149 @@ stages:
runOnce:
deploy:
steps:
- task: PowerShell@2
displayName: Output Deployment Parameters
condition: contains(variables['system.debug'], 'true')
inputs:
targetType: inline
script: |
Write-Host "DeploymentType: ${{parameters.DeploymentType}}"
Write-Host "DependsOn: ${{parameters.DependsOn}}"
Write-Host "ApplicationName: ${{parameters.ApplicationName}}"
Write-Host "PublishFolder: ${{parameters.PublishFolder}}"
Write-Host "RepositoryFolder: ${{parameters.RepositoryFolder}}"
pwsh: true
- task: PowerShell@2
displayName: Output Deployment Parameters
condition: contains(variables['system.debug'], 'true')
inputs:
targetType: inline
script: |
Write-Host "DeploymentType: ${{parameters.DeploymentType}}"
Write-Host "DependsOn: ${{parameters.DependsOn}}"
Write-Host "ApplicationName: ${{parameters.ApplicationName}}"
Write-Host "PublishFolder: ${{parameters.PublishFolder}}"
Write-Host "RepositoryFolder: ${{parameters.RepositoryFolder}}"
pwsh: true
- template: output-environment-variables.yml@self
- template: output-environment-variables.yml@self
- checkout: MasterRepo
enabled: false
persistCredentials: true
- checkout: MasterRepo
enabled: false
persistCredentials: true
- task: PowerShell@2
displayName: Pull Master Repository Files
enabled: false
env:
DEPLOY_BUILDNUMBER: $(Build.BuildNumber)
DEPLOY_SOURCESDIRECTORY: $(Build.SourcesDirectory)
inputs:
targetType: inline
script: |
Write-Host "Setting up the global configuration"
git config --global user.email "${{parameters.GitEmail}}"
git config --global user.name "${{parameters.GitUsername}}"
- task: PowerShell@2
displayName: Pull Master Repository Files
enabled: false
env:
DEPLOY_BUILDNUMBER: $(Build.BuildNumber)
DEPLOY_SOURCESDIRECTORY: $(Build.SourcesDirectory)
inputs:
targetType: inline
script: |
Write-Host "Setting up the global configuration"
git config --global user.email "${{parameters.GitEmail}}"
git config --global user.name "${{parameters.GitUsername}}"
Write-Host "Performing Git Checkout"
git checkout -b master
Write-Host "Performing Git Checkout"
git checkout -b master
Write-Host "Performing Git Fetch"
git fetch
Write-Host "Performing Git Fetch"
git fetch
Write-Host "Performing Git Branch"
git branch --set-upstream-to=origin/master master
Write-Host "Performing Git Branch"
git branch --set-upstream-to=origin/master master
Write-Host "Performing Git Pull"
git pull --force
pwsh: true
workingDirectory: '$(Build.SourcesDirectory)'
Write-Host "Performing Git Pull"
git pull --force
pwsh: true
workingDirectory: '$(Build.SourcesDirectory)'
- task: PowerShell@2
displayName: Copy ${{parameters.DeploymentType}} Files
enabled: false
env:
DEPLOY_BUILDNUMBER: $(Build.BuildNumber)
DEPLOY_PUBLISHDIRECTORY: "$(Agent.BuildDirectory)/${{parameters.PublishFolder}}"
DEPLOY_REPODIRECTORY: "$(Build.SourcesDirectory)/${{parameters.RepositoryFolder}}"
inputs:
targetType: inline
script: |
$appVersion = $env:DEPLOY_BUILDNUMBER
$appVersionShort = $appVersion.Substring(0, $appVersion.LastIndexOf('.'))
- task: PowerShell@2
displayName: Copy ${{parameters.DeploymentType}} Files
enabled: false
env:
DEPLOY_BUILDNUMBER: $(Build.BuildNumber)
DEPLOY_PUBLISHDIRECTORY: "$(Agent.BuildDirectory)/${{parameters.PublishFolder}}"
DEPLOY_REPODIRECTORY: "$(Build.SourcesDirectory)/${{parameters.RepositoryFolder}}"
inputs:
targetType: inline
script: |
$appVersion = $env:DEPLOY_BUILDNUMBER
$appVersionShort = $appVersion.Substring(0, $appVersion.LastIndexOf('.'))
if (!(Test-Path $env:DEPLOY_PUBLISHDIRECTORY)) {
throw "Source directory does not exist or could not be found ($env:DEPLOY_PUBLISHDIRECTORY)"
}
if (!(Test-Path $env:DEPLOY_REPODIRECTORY)) {
New-Item -Path "$env:DEPLOY_REPODIRECTORY" -ItemType Directory -Force
}
if (!(Test-Path $env:DEPLOY_PUBLISHDIRECTORY)) {
throw "Source directory does not exist or could not be found ($env:DEPLOY_PUBLISHDIRECTORY)"
}
if (!(Test-Path $env:DEPLOY_REPODIRECTORY)) {
New-Item -Path "$env:DEPLOY_REPODIRECTORY" -ItemType Directory -Force
}
# copy common files
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\en-US.xaml" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\latest.zip" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
# copy common files
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\en-US.xaml" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\latest.zip" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
# copy beta specific files
if ('${{parameters.DeploymentType}}' -eq 'Beta') {
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\latestBeta.txt" -Destination "$env:DEPLOY_REPODIRECTORY\latest.txt" -Force
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\VersionFeedBeta.xml" -Destination "$env:DEPLOY_REPODIRECTORY\VersionFeed.xml" -Force
}
# copy beta specific files
if ('${{parameters.DeploymentType}}' -eq 'Beta') {
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\latestBeta.txt" -Destination "$env:DEPLOY_REPODIRECTORY\latest.txt" -Force
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\VersionFeedBeta.xml" -Destination "$env:DEPLOY_REPODIRECTORY\VersionFeed.xml" -Force
}
# copy production specific files
if ('${{parameters.DeploymentType}}' -eq 'Production') {
$applicationFilenamePrefix = "${{parameters.ApplicationName}}_$appVersionShort"
# copy production specific files
if ('${{parameters.DeploymentType}}' -eq 'Production') {
$applicationFilenamePrefix = "${{parameters.ApplicationName}}_$appVersionShort"
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\$applicationFilenamePrefix.exe" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\$applicationFilenamePrefix.zip" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\latest.exe" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\latest.txt" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\VersionFeed.xml" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
}
pwsh: true
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\$applicationFilenamePrefix.exe" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\$applicationFilenamePrefix.zip" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\latest.exe" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\latest.txt" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\VersionFeed.xml" -Destination "$env:DEPLOY_REPODIRECTORY" -Force
}
pwsh: true
- task: PowerShell@2
displayName: Commit ${{parameters.DeploymentType}} Files
enabled: false
env:
DEPLOY_BUILDNUMBER: $(Build.BuildNumber)
DEPLOY_SOURCESDIRECTORY: $(Build.SourcesDirectory)
inputs:
targetType: inline
script: |
$appVersion = $env:DEPLOY_BUILDNUMBER
$appVersionShort = $appVersion.Substring(0, $appVersion.LastIndexOf('.'))
- task: PowerShell@2
displayName: Commit ${{parameters.DeploymentType}} Files
enabled: false
env:
DEPLOY_BUILDNUMBER: $(Build.BuildNumber)
DEPLOY_SOURCESDIRECTORY: $(Build.SourcesDirectory)
inputs:
targetType: inline
script: |
$appVersion = $env:DEPLOY_BUILDNUMBER
$appVersionShort = $appVersion.Substring(0, $appVersion.LastIndexOf('.'))
Write-Host "Setting up the global configuration"
git config --global user.email "${{parameters.GitEmail}}"
git config --global user.name "${{parameters.GitUsername}}"
Write-Host "Setting up the global configuration"
git config --global user.email "${{parameters.GitEmail}}"
git config --global user.name "${{parameters.GitUsername}}"
Write-Host "Performing Git Add"
git add -A
Write-Host "Performing Git Add"
git add -A
Write-Host "Performing Git Commit"
if ('${{parameters.DeploymentType}}' -eq 'Beta') {
git commit -m "${{parameters.ApplicationName}} Beta $appVersion"
}
Write-Host "Performing Git Commit"
if ('${{parameters.DeploymentType}}' -eq 'Beta') {
git commit -m "${{parameters.ApplicationName}} Beta $appVersion"
}
if ('${{parameters.DeploymentType}}' -eq 'Production') {
git commit -m "${{parameters.ApplicationName}} $appVersionShort"
}
if ('${{parameters.DeploymentType}}' -eq 'Production') {
git commit -m "${{parameters.ApplicationName}} $appVersionShort"
}
Write-Host "Performing Git Push"
git push --set-upstream origin master --porcelain --force
pwsh: true
workingDirectory: '$(Build.SourcesDirectory)'
- task: PowerShell@2
displayName: 'Update VersionBuild Variable'
condition: eq('${{parameters.DeploymentType}}', 'Production')
enabled: false
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
inputs:
targetType: filePath
filePath: './.azure/scripts/UpdateVersionVariable.ps1'
arguments: "-variableName 'VersionBuild'"
pwsh: true
Write-Host "Performing Git Push"
git push --set-upstream origin master --porcelain --force
pwsh: true
workingDirectory: '$(Build.SourcesDirectory)'
- task: PowerShell@2
displayName: 'Update VersionRevision Variable'
condition: eq('${{parameters.DeploymentType}}', 'Beta')
enabled: true
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
inputs:
targetType: filePath
filePath: './.azure/scripts/UpdateVersionVariable.ps1'
pwsh: true
- task: PowerShell@2
displayName: 'Reset VersionRevision Variable'
condition: eq('${{parameters.DeploymentType}}', 'Production')
enabled: false
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
VERSIONREVISION: 0
inputs:
targetType: filePath
filePath: './.azure/scripts/UpdateVersionVariable.ps1'
arguments: "-variableName 'VersionRevision'"
pwsh: true
- template: azure-pipelines-clean-agent.yml@self
- ${{ if eq(parameters.DeploymentType, 'Beta') }}:
- template: update-pipeline-variable.yml@self
parameters:
CleanArtifactsFolder: true
CleanBinariesFolder: true
CleanSourcesFolder: true
CleanPublishFolder: true
PublishFolder: $(PublishFolder)
VariableName: 'VersionRevision'
VariableValue: $(VersionRevision) + 1
- ${{ if eq(parameters.DeploymentType, 'Production') }}:
- template: update-pipeline-variable.yml@self
parameters:
VariableName: 'VersionBuild'
VariableValue: $(VersionBuild) + 1
- ${{ if eq(parameters.DeploymentType, 'Production') }}:
- template: update-pipeline-variable.yml@self
parameters:
VariableName: 'VersionRevision'
VariableValue: 1
- template: azure-pipelines-clean-agent.yml@self
parameters:
CleanArtifactsFolder: true
CleanBinariesFolder: true
CleanSourcesFolder: true
CleanPublishFolder: true
PublishFolder: $(PublishFolder)

View file

@ -0,0 +1,58 @@
parameters:
- name: VariableName
displayName: Variable Name
- name: VariableValue
displayName: Variable Value
steps:
- task: PowerShell@2
displayName: Update Pipeline Variable - ${{parameters.VariableName}}
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
inputs:
targetType: inline
script: |
[string]$repositoryUrl = $env:SYSTEM_COLLECTIONURI
[string]$repositoryName = $env:SYSTEM_TEAMPROJECT
[string]$definitionId = $env:SYSTEM_DEFINITIONID
[string]$variableName = ${{parameters.VariableName}}
[string]$variableValue = ${{parameters.VariableValue}}
[string]$accessToken = $env:SYSTEM_ACCESSTOKEN
[string]$debugMode = $env.SYSTEM_DEBUG
if ($debugMode -eq 'true') {
Write-Host '##[section]Starting: DEBUG INFORMATION'
Write-Host "##[debug]repositoryUrl = $repositoryUrl"
Write-Host "##[debug]repositoryName = $repositoryName"
Write-Host "##[debug]definitionId = $definitionId"
Write-Host "##[debug]variableName = $variableName"
Write-Host "##[debug]variableValue = $variableValue"
Write-Host '##[section]Finishing: DEBUG INFORMATION'
Write-Host ''
}
if($repositoryUrl.EndsWith('/')) {
$repositoryUrl = $repositoryUrl.TrimEnd('/')
}
$headers = @{
'Authorization' = "Bearer $accessToken"
}
# Get an overview of the build definition
$definitionUrl = "$repositoryUrl/$repositoryName/_apis/build/Definitions/$($definitionId)?api-version=5.0"
$definitionResponse = Invoke-RestMethod -Method Get -Uri $definitionUrl -Headers $headers -UseBasicParsing
# If the build has the variable, update it.
if ($definitionResponse.variables.$variableName) {
$oldValue = $definitionResponse.variables.$variableName.value
$definitionResponse.variables.$variableName.value = $variableValue
Write-Output -InputObject "Updating $variableName from $($oldValue) to $($variableValue)..."
$body = ConvertTo-Json -InputObject $definitionResponse -Depth 100 -Compress
$response = Invoke-RestMethod -Method Put -Uri $definitionsUrl -Headers $headers -ContentType 'application/json' -Body $body -UseBasicParsing
}
pwsh: true