parameters: - name: DeploymentType displayName: Type of Deployment Stage type: string values: - Beta - Production - name: DependsOn displayName: Depends On type: string - name: ApplicationName type: string - name: PublishFolder type: string - name: RepositoryFolder type: string - name: GitEmail type: string - name: GitUsername type: string stages: - stage: deploy${{parameters.DeploymentType}} displayName: ${{parameters.DeploymentType}} lockBehavior: runLatest condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/source')) dependsOn: - build - ${{ if ne(parameters.DependsOn, 'build') }}: - deploy${{parameters.DependsOn}} jobs: - deployment: deploy${{parameters.DeploymentType}} displayName: Deploy ${{parameters.DeploymentType}} environment: github-servermanager-${{ lower(parameters.DeploymentType) }} workspace: clean: all strategy: 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 - template: output-environment-variables.yml@self - checkout: MasterRepo persistCredentials: true - task: PowerShell@2 displayName: Pull Master Repository Files 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 "Setting up the configuration" #git config pull.rebase false Write-Host "Performing Git Checkout" git checkout -b master Write-Host "Performing Git Branch" git branch --set-upstream-to=origin/master master Write-Host "Performing a Git Pull" git pull --force pwsh: true workingDirectory: '$(Build.SourcesDirectory)' - task: PowerShell@2 displayName: Copy ${{parameters.DeploymentType}} Files 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 } # 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 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 - 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 configuration" git config pull.rebase false #Write-Host "Performing Git Checkout" #git checkout -b master 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" } 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 - task: PowerShell@2 displayName: 'Update VersionRevision Variable' condition: eq('${{parameters.DeploymentType}}', 'Beta') enabled: false 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 - task: PowerShell@2 displayName: Update Pipeline Version Variables (TODO) enabled: false env: SYSTEM_ACCESSTOKEN: $(System.AccessToken) inputs: targetType: inline script: | if ('${{parameters.DeploymentType}}' -eq 'Beta') { Write-Host "Updating beta pipeline variables" } if ('${{parameters.DeploymentType}}' -eq 'Production') { Write-Host "Updating production pipeline variables" } pwsh: true - template: azure-pipelines-clean-agent.yml@self parameters: CleanArtifactsFolder: false CleanBinariesFolder: false CleanSourcesFolder: false CleanPublishFolder: false PublishFolder: $(PublishFolder)