Introduction
Another way how the Release pipeline can make life easier.
YML file
After that you have to create build pipeline using this yml file.
Source code:
trigger: branches: include: - master pool: name: NavBizDev01 workspace: clean: all steps: - checkout: self - task: PowerShell@2 displayName: 'Copy Licenses' inputs: targetType: filePath filePath: 'CopyLicenses.ps1' errorActionPreference: stop failOnStderr: true - task: PublishBuildArtifacts@1 inputs: pathtoPublish: '$(Build.StagingDirectory)' artifactName: Artifacts
Copy-Item -Path ($env:Build_SourcesDirectory + "\Licenses\") -Destination $env:Build_StagingDirectory -Recurse Copy-Item -Path ($env:Build_SourcesDirectory + "\Config\") -Destination $env:Build_StagingDirectory -Recurse Copy-Item -Path (Join-Path $env:Build_SourcesDirectory -ChildPath("\ImportLicense.ps1")) -Destination $env:Build_StagingDirectory Copy-Item -Path (Join-Path $env:Build_SourcesDirectory -ChildPath("\CreateContainer.ps1")) -Destination $env:Build_StagingDirectory
Add licenses to some repo
Release pipeline
In your project create release pipeline
Script path:
$(System.DefaultWorkingDirectory)/$(Release.PrimaryArtifactSourceAlias)/Artifacts/ImportLicense.ps1
$ArtifactsDirectory = (Join-Path -Path $env:System_ArtifactsDirectory -ChildPath ($env:Release_PrimaryArtifactSourceAlias + '\Artifacts')) $settings = (Get-Content (Join-Path -Path $ArtifactsDirectory -ChildPath ("Config\" + $env:ConfigFile)) -Encoding UTF8 | ConvertFrom-Json) import-module $env:NAVADMINTOOL | Out-Null foreach ($Configuration in $settings.configurations) { $LicenseFile = Join-Path $ArtifactsDirectory -ChildPath("Licenses\" + $env:LicenseFile) Import-NAVServerLicense -LicenseFile $LicenseFile -ServerInstance $configuration.serverInstance Restart-NAVServerInstance -ServerInstance $configuration.serverInstance Export-NAVServerLicenseInformation -ServerInstance $configuration.serverInstance } Remove-Item -Path (Join-Path $ArtifactsDirectory -ChildPath("Licenses\")) -Recurse -Force
Conclusion
And in this way, the Release pipeline can be easily utilized to upload licenses, avoiding the need to do all of that manually.
Instead of adding licenses to the repository, a better option is to place licenses in Azure Key Vault and use them as secrets in the pipeline. I hope to find the time to explore that and dedicate a post to that approach.
Add comment
Comments