Continuous integration pipelines are the same for all micro services. They have been implemented thanks to an Azure pipeline template : https://github.com/ygo74/Inventory.API/blob/master/builds/pipelines/templates/service-build-ci.yaml
the pipeline provides the following features :
- Identify the build context (a.k.a Identify the build version)
- Build and unit tests the service
- Build the database script
- Store the built artefacts into the pipeline to be reused by the deployment pipeline
Table of contents
Versioning
First tasks of pipeline have to identify the version number of the current build.
Versioning management process not yet finished
Goal is to use semantic versioning and also ensure to create a unique version of build. This task shouldn’t be under the developer responsibility.
The versioning process is based on a git release flow and a custom Azure pipeline task has been created to implement the rules but it is not yet finished
Service Build and unit tests
Build service
-
Dotnet build
The build is done thanks to standard task DotNetCoreCLI@2. The version number comes from the versioning tasks
The task needs the following arguments:
- service’s name
- Dotnet project path
- the variable’s name which contains the version number
- task: DotNetCoreCLI@2 displayName: Build ${{ parameters.serviceName }} inputs: command: 'build' projects: '${{ parameters.projectPath }}' versioningScheme: byEnvVar versionEnvVar: 'CalculateNextVersion.version'
-
Snyk security scan
The security scan is done thanks the snyk task SnykSecurityScan@1 retrieved from the Snyk Security Scan extension.
the task needs the following arguments :
- Service’s name
- Snyk organization’s name
- Test type
- Test directory
# Find the project directory from the csproj file path - task: PowerShell@2 displayName: Set project directory path inputs: targetType: 'inline' script: | # Get project directory path $projectPath = "${{ parameters.projectPath }}" $directoryPath = Get-Item -Path $projectPath | Select-Object -ExpandProperty Directory | Resolve-Path | Select-Object -ExpandProperty Path echo "Project directory path : $directoryPath" echo "##vso[task.setvariable variable=directoryPath]$directoryPath" failOnStderr: true pwsh: true # Scan service vulnerabilities - task: SnykSecurityScan@1 inputs: serviceConnectionEndpoint: 'Snyk' testType: 'app' severityThreshold: 'high' monitorWhen: 'always' failOnIssues: true projectName: '${{ parameters.serviceName }}' organization: 'ygo74' testDirectory: '$(directoryPath)'