Thursday, January 19, 2023

Submit .Net class library to Azure Artifacts Feed

 Azure Artifacts feed provides great means to share the common reusable components across your organization. In the following code base I will display a template for Azure DevOps build pipeline. 

trigger:
- 'main'

pool:
vmImage: ubuntu-latest
demands:
- npm

variables:
buildConfiguration: 'Release'
dotNetFramework: 'net7.0'
targetRuntime: 'linux-x64'
moduleName: 'ModuleName'
entityTypeName: 'EntityType'
// Once you create a feed, that ID will be added here.
vstsFeedId: '<A Guid>'
major: '1'
minor: '0'
revision: $[counter(variables['minor'], 1)]
nugetVersion: '$(major).$(minor).$(revision)'

steps:
- task: NuGetAuthenticate@1
inputs:
forceReinstallCredentialProvider: true

// Optional: Run unit tests
- task: DotNetCoreCLI@2
displayName: 'Run unit tests - $(buildConfiguration)'
inputs:
command: 'test'
arguments: '--framework $(dotNetFramework) --configuration $(buildConfiguration)'
publishTestResults: true
projects: '**/*.Tests.csproj'

// Does packaging. Nuget version is automatically increased to next revision.
- task: NuGetCommand@2
displayName: 'Nuget Pack'
inputs:
command: 'pack'
packagesToPack: '**/$(moduleName).$(entityTypeName).csproj'
versionEnvVar: 'nugetVersion'
versioningScheme: 'byEnvVar'
packDestination: '$(Build.ArtifactStagingDirectory)'

- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
publishLocation: 'pipeline'

- task: NuGetCommand@2
displayName: 'Nuget Push'
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: '$(vstsFeedId)'

Sunday, January 8, 2023

Setting up App Config values with Bicep

There are often times where we need to setup a master configuration instance for the config values that might be referenced within pipelines. In such situations we can setup the initial configs such as environment name initially. 

First of all we will initialise a set of key value names. 

param keyValueNames array = [
  'appName$dev'
  'environmentType$dev'
  'Acr_Name$dev'
  'region$dev-${region}'
]