From 57b640655cccf12e97162c55d458fef36563805b Mon Sep 17 00:00:00 2001 From: EVANS Date: Tue, 8 Mar 2022 14:00:09 +0000 Subject: [PATCH 1/3] Added SonarCloud setup and YAML refactoring --- azure-pipelines.yml | 109 ++---------------------- pipeline-templates/job/code-build.yml | 93 ++++++++++++++++++++ pipeline-templates/job/dacpac-build.yml | 25 ++++++ 3 files changed, 125 insertions(+), 102 deletions(-) create mode 100644 pipeline-templates/job/code-build.yml create mode 100644 pipeline-templates/job/dacpac-build.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b79919f..fabcf23 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -2,9 +2,7 @@ trigger: batch: true branches: include: - - "*" - -pr: none + - "master" variables: buildConfiguration: "release" @@ -15,104 +13,11 @@ resources: - repository: das-platform-building-blocks type: github name: SkillsFundingAgency/das-platform-building-blocks - ref: refs/tags/0.4.34 + ref: refs/tags/0.4.37 endpoint: SkillsFundingAgency -jobs: - - job: 'CodeBuild' - pool: - name: 'DAS - Continuous Integration' - workspace: - clean: all - steps: - - task: gittools.gitversion.gitversion-task.GitVersion@5 - displayName: GitVersion - inputs: - updateAssemblyInfo: true - - - task: DotNetCoreCLI@2 - displayName: Restore - inputs: - command: restore - projects: "src/**/*.csproj" - nugetConfigPath: "src/nuget.config" - feedsToUse: config - - - task: DotNetCoreCLI@2 - displayName: Build - inputs: - projects: "src/**/*.csproj" - arguments: "--configuration $(buildConfiguration) --no-restore" - - - task: DotNetCoreCLI@2 - displayName: Test - inputs: - command: test - projects: "**/*Tests.csproj" - arguments: "--configuration $(buildConfiguration) --no-build" - - - template: azure-pipelines-templates/build/step/dependency-check.yml@das-platform-building-blocks - - - task: DotNetCoreCLI@2 - displayName: "Publish API" - inputs: - command: publish - publishWebProjects: false - projects: "src/SFA.DAS.Notifications.Api/SFA.DAS.Notifications.Api.csproj" - arguments: "--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)/publish --no-restore --no-build" - - - task: DotNetCoreCLI@2 - displayName: "Publish Web Job" - inputs: - command: publish - publishWebProjects: false - projects: "src/SFA.DAS.Notifications.MessageHandlers/SFA.DAS.Notifications.MessageHandlers.csproj" - arguments: "--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)/publish/SFA.DAS.Notifications.MessageHandlers/App_Data/jobs/continuous/Notifications-MessageHandlers --no-restore --no-build" - zipAfterPublish: false - modifyOutputPath: false - - task: DotNetCoreCLI@2 - displayName: "dotnet pack" - inputs: - command: pack - packagesToPack: > - src/SFA.DAS.Notifications.Messages/SFA.DAS.Notifications.Messages.csproj - packDirectory: "$(build.artifactstagingdirectory)/publish" - versioningScheme: byBuildNumber - buildProperties: 'Version="$(Build.BuildNumber)"' - - - task: CopyFiles@2 - displayName: "Copy Files to: $(build.artifactstagingdirectory)" - inputs: - contents: | - azure/** - targetFolder: "$(build.artifactstagingdirectory)/publish" - - - task: PublishBuildArtifacts@1 - displayName: "Publish Artifact" - inputs: - pathtoPublish: "$(build.artifactstagingdirectory)/publish" - - - job: 'DACPACBuild' - pool: - vmImage: 'windows-2019' - workspace: - clean: all - steps: - - task: VSBuild@1 - displayName: 'Build DACPAC' - inputs: - solution: 'src/SFA.DAS.Notifications.Database/SFA.DAS.Notifications.Database.sqlproj' - platform: '$(buildPlatform)' - configuration: '$(buildConfiguration)' - msbuildArgs: '/p:PackageLocation="$(build.artifactstagingdirectory)/publish"' - - task: CopyFiles@2 - displayName: 'Copy Files to: $(build.artifactstagingdirectory)' - inputs: - contents: | - src/**/*.dacpac - targetFolder: '$(build.artifactstagingdirectory)/publish' - flattenfolders: true - - task: PublishBuildArtifacts@1 - displayName: 'Publish Artifact' - inputs: - pathtoPublish: '$(build.artifactstagingdirectory)/publish' \ No newline at end of file +stages: +- stage: Build + jobs: + - template: pipeline-templates/job/code-build.yml + - template: pipeline-templates/job/dacpac-build.yml \ No newline at end of file diff --git a/pipeline-templates/job/code-build.yml b/pipeline-templates/job/code-build.yml new file mode 100644 index 0000000..ece0e46 --- /dev/null +++ b/pipeline-templates/job/code-build.yml @@ -0,0 +1,93 @@ +jobs: +- job: 'CodeBuild' + pool: + name: 'DAS - Continuous Integration' + workspace: + clean: all + steps: + - task: gittools.gitversion.gitversion-task.GitVersion@5 + displayName: GitVersion + inputs: + updateAssemblyInfo: true + + - task: SonarCloudPrepare@1 + displayName: Prepare SonarCloud analysis configuration + condition: and(succeeded(), or(in(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/heads/main'), eq(variables['Build.Reason'], 'PullRequest'))) + inputs: + SonarCloud: ESFA - SonarCloud + organization: $(SonarCloudOrganisationKey) + scannerMode: MSBuild + projectName: "$(Build.DefinitionName)" + projectKey: SkillsFundingAgency_das-referencedata + + - task: DotNetCoreCLI@2 + displayName: Restore + inputs: + command: restore + projects: "src/**/*.csproj" + nugetConfigPath: "src/nuget.config" + feedsToUse: config + + - task: DotNetCoreCLI@2 + displayName: Build + inputs: + projects: "src/**/*.csproj" + arguments: "--configuration $(buildConfiguration) --no-restore" + + - task: DotNetCoreCLI@2 + displayName: Test + inputs: + command: test + projects: "**/*Tests.csproj" + arguments: "--configuration $(buildConfiguration) --no-build" + + - template: azure-pipelines-templates/build/step/dependency-check.yml@das-platform-building-blocks + + - task: DotNetCoreCLI@2 + displayName: "Publish API" + inputs: + command: publish + publishWebProjects: false + projects: "src/SFA.DAS.Notifications.Api/SFA.DAS.Notifications.Api.csproj" + arguments: "--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)/publish --no-restore --no-build" + + - task: DotNetCoreCLI@2 + displayName: "Publish Web Job" + inputs: + command: publish + publishWebProjects: false + projects: "src/SFA.DAS.Notifications.MessageHandlers/SFA.DAS.Notifications.MessageHandlers.csproj" + arguments: "--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)/publish/SFA.DAS.Notifications.MessageHandlers/App_Data/jobs/continuous/Notifications-MessageHandlers --no-restore --no-build" + zipAfterPublish: false + modifyOutputPath: false + - task: DotNetCoreCLI@2 + displayName: "dotnet pack" + inputs: + command: pack + packagesToPack: > + src/SFA.DAS.Notifications.Messages/SFA.DAS.Notifications.Messages.csproj + packDirectory: "$(build.artifactstagingdirectory)/publish" + versioningScheme: byBuildNumber + buildProperties: 'Version="$(Build.BuildNumber)"' + + - task: SonarCloudAnalyze@1 + displayName: Run SonarCloud analysis + condition: and(succeeded(), or(in(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/heads/main'), eq(variables['Build.Reason'], 'PullRequest'))) + + - task: SonarCloudPublish@1 + displayName: Publish SonarCloud analysis results on build summary + condition: and(succeeded(), or(in(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/heads/main'), eq(variables['Build.Reason'], 'PullRequest'))) + inputs: + pollingTimeoutSec: '300' + + - task: CopyFiles@2 + displayName: "Copy Files to: $(build.artifactstagingdirectory)" + inputs: + contents: | + azure/** + targetFolder: "$(build.artifactstagingdirectory)/publish" + + - task: PublishBuildArtifacts@1 + displayName: "Publish Artifact" + inputs: + pathtoPublish: "$(build.artifactstagingdirectory)/publish" \ No newline at end of file diff --git a/pipeline-templates/job/dacpac-build.yml b/pipeline-templates/job/dacpac-build.yml new file mode 100644 index 0000000..3c4ce27 --- /dev/null +++ b/pipeline-templates/job/dacpac-build.yml @@ -0,0 +1,25 @@ +jobs: +- job: 'DACPACBuild' + pool: + vmImage: 'windows-2019' + workspace: + clean: all + steps: + - task: VSBuild@1 + displayName: 'Build DACPAC' + inputs: + solution: 'src/SFA.DAS.Notifications.Database/SFA.DAS.Notifications.Database.sqlproj' + platform: '$(buildPlatform)' + configuration: '$(buildConfiguration)' + msbuildArgs: '/p:PackageLocation="$(build.artifactstagingdirectory)/publish"' + - task: CopyFiles@2 + displayName: 'Copy Files to: $(build.artifactstagingdirectory)' + inputs: + contents: | + src/**/*.dacpac + targetFolder: '$(build.artifactstagingdirectory)/publish' + flattenfolders: true + - task: PublishBuildArtifacts@1 + displayName: 'Publish Artifact' + inputs: + pathtoPublish: '$(build.artifactstagingdirectory)/publish' \ No newline at end of file From d97095aaef345625f392bde74408fcdb4e47ede9 Mon Sep 17 00:00:00 2001 From: EVANS Date: Tue, 8 Mar 2022 14:03:10 +0000 Subject: [PATCH 2/3] Corrected indentation on dacpac build --- pipeline-templates/job/dacpac-build.yml | 46 ++++++++++++------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/pipeline-templates/job/dacpac-build.yml b/pipeline-templates/job/dacpac-build.yml index 3c4ce27..d94f5bd 100644 --- a/pipeline-templates/job/dacpac-build.yml +++ b/pipeline-templates/job/dacpac-build.yml @@ -1,25 +1,25 @@ jobs: - job: 'DACPACBuild' - pool: - vmImage: 'windows-2019' - workspace: - clean: all - steps: - - task: VSBuild@1 - displayName: 'Build DACPAC' - inputs: - solution: 'src/SFA.DAS.Notifications.Database/SFA.DAS.Notifications.Database.sqlproj' - platform: '$(buildPlatform)' - configuration: '$(buildConfiguration)' - msbuildArgs: '/p:PackageLocation="$(build.artifactstagingdirectory)/publish"' - - task: CopyFiles@2 - displayName: 'Copy Files to: $(build.artifactstagingdirectory)' - inputs: - contents: | - src/**/*.dacpac - targetFolder: '$(build.artifactstagingdirectory)/publish' - flattenfolders: true - - task: PublishBuildArtifacts@1 - displayName: 'Publish Artifact' - inputs: - pathtoPublish: '$(build.artifactstagingdirectory)/publish' \ No newline at end of file + pool: + vmImage: 'windows-2019' + workspace: + clean: all + steps: + - task: VSBuild@1 + displayName: 'Build DACPAC' + inputs: + solution: 'src/SFA.DAS.Notifications.Database/SFA.DAS.Notifications.Database.sqlproj' + platform: '$(buildPlatform)' + configuration: '$(buildConfiguration)' + msbuildArgs: '/p:PackageLocation="$(build.artifactstagingdirectory)/publish"' + - task: CopyFiles@2 + displayName: 'Copy Files to: $(build.artifactstagingdirectory)' + inputs: + contents: | + src/**/*.dacpac + targetFolder: '$(build.artifactstagingdirectory)/publish' + flattenfolders: true + - task: PublishBuildArtifacts@1 + displayName: 'Publish Artifact' + inputs: + pathtoPublish: '$(build.artifactstagingdirectory)/publish' \ No newline at end of file From 57e11041498076557a4f66969403e2141846bc0d Mon Sep 17 00:00:00 2001 From: EVANS Date: Tue, 8 Mar 2022 14:05:05 +0000 Subject: [PATCH 3/3] Added var group and corrected formatting in code-build --- pipeline-templates/job/code-build.yml | 155 +++++++++++++------------- 1 file changed, 80 insertions(+), 75 deletions(-) diff --git a/pipeline-templates/job/code-build.yml b/pipeline-templates/job/code-build.yml index ece0e46..aa430dc 100644 --- a/pipeline-templates/job/code-build.yml +++ b/pipeline-templates/job/code-build.yml @@ -2,92 +2,97 @@ jobs: - job: 'CodeBuild' pool: name: 'DAS - Continuous Integration' + variables: + - group: BUILD Management Resources + - name: buildConfiguration + value: release workspace: clean: all steps: - - task: gittools.gitversion.gitversion-task.GitVersion@5 - displayName: GitVersion - inputs: - updateAssemblyInfo: true + - task: gittools.gitversion.gitversion-task.GitVersion@5 + displayName: GitVersion + inputs: + updateAssemblyInfo: true - - task: SonarCloudPrepare@1 - displayName: Prepare SonarCloud analysis configuration - condition: and(succeeded(), or(in(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/heads/main'), eq(variables['Build.Reason'], 'PullRequest'))) - inputs: - SonarCloud: ESFA - SonarCloud - organization: $(SonarCloudOrganisationKey) - scannerMode: MSBuild - projectName: "$(Build.DefinitionName)" - projectKey: SkillsFundingAgency_das-referencedata + - task: SonarCloudPrepare@1 + displayName: Prepare SonarCloud analysis configuration + condition: and(succeeded(), or(in(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/heads/main'), eq(variables['Build.Reason'], 'PullRequest'))) + inputs: + SonarCloud: ESFA - SonarCloud + organization: $(SonarCloudOrganisationKey) + scannerMode: MSBuild + projectName: "$(Build.DefinitionName)" + projectKey: SkillsFundingAgency_das-referencedata - - task: DotNetCoreCLI@2 - displayName: Restore - inputs: - command: restore - projects: "src/**/*.csproj" - nugetConfigPath: "src/nuget.config" - feedsToUse: config + - task: DotNetCoreCLI@2 + displayName: Restore + inputs: + command: restore + projects: "src/**/*.csproj" + nugetConfigPath: "src/nuget.config" + feedsToUse: config - - task: DotNetCoreCLI@2 - displayName: Build - inputs: - projects: "src/**/*.csproj" - arguments: "--configuration $(buildConfiguration) --no-restore" + - task: DotNetCoreCLI@2 + displayName: Build + inputs: + projects: "src/**/*.csproj" + arguments: "--configuration $(buildConfiguration) --no-restore" - - task: DotNetCoreCLI@2 - displayName: Test - inputs: - command: test - projects: "**/*Tests.csproj" - arguments: "--configuration $(buildConfiguration) --no-build" + - task: DotNetCoreCLI@2 + displayName: Test + inputs: + command: test + projects: "**/*Tests.csproj" + arguments: "--configuration $(buildConfiguration) --no-build" - - template: azure-pipelines-templates/build/step/dependency-check.yml@das-platform-building-blocks + - template: azure-pipelines-templates/build/step/dependency-check.yml@das-platform-building-blocks - - task: DotNetCoreCLI@2 - displayName: "Publish API" - inputs: - command: publish - publishWebProjects: false - projects: "src/SFA.DAS.Notifications.Api/SFA.DAS.Notifications.Api.csproj" - arguments: "--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)/publish --no-restore --no-build" + - task: DotNetCoreCLI@2 + displayName: "Publish API" + inputs: + command: publish + publishWebProjects: false + projects: "src/SFA.DAS.Notifications.Api/SFA.DAS.Notifications.Api.csproj" + arguments: "--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)/publish --no-restore --no-build" - - task: DotNetCoreCLI@2 - displayName: "Publish Web Job" - inputs: - command: publish - publishWebProjects: false - projects: "src/SFA.DAS.Notifications.MessageHandlers/SFA.DAS.Notifications.MessageHandlers.csproj" - arguments: "--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)/publish/SFA.DAS.Notifications.MessageHandlers/App_Data/jobs/continuous/Notifications-MessageHandlers --no-restore --no-build" - zipAfterPublish: false - modifyOutputPath: false - - task: DotNetCoreCLI@2 - displayName: "dotnet pack" - inputs: - command: pack - packagesToPack: > - src/SFA.DAS.Notifications.Messages/SFA.DAS.Notifications.Messages.csproj - packDirectory: "$(build.artifactstagingdirectory)/publish" - versioningScheme: byBuildNumber - buildProperties: 'Version="$(Build.BuildNumber)"' + - task: DotNetCoreCLI@2 + displayName: "Publish Web Job" + inputs: + command: publish + publishWebProjects: false + projects: "src/SFA.DAS.Notifications.MessageHandlers/SFA.DAS.Notifications.MessageHandlers.csproj" + arguments: "--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)/publish/SFA.DAS.Notifications.MessageHandlers/App_Data/jobs/continuous/Notifications-MessageHandlers --no-restore --no-build" + zipAfterPublish: false + modifyOutputPath: false + + - task: DotNetCoreCLI@2 + displayName: "dotnet pack" + inputs: + command: pack + packagesToPack: > + src/SFA.DAS.Notifications.Messages/SFA.DAS.Notifications.Messages.csproj + packDirectory: "$(build.artifactstagingdirectory)/publish" + versioningScheme: byBuildNumber + buildProperties: 'Version="$(Build.BuildNumber)"' - - task: SonarCloudAnalyze@1 - displayName: Run SonarCloud analysis - condition: and(succeeded(), or(in(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/heads/main'), eq(variables['Build.Reason'], 'PullRequest'))) + - task: SonarCloudAnalyze@1 + displayName: Run SonarCloud analysis + condition: and(succeeded(), or(in(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/heads/main'), eq(variables['Build.Reason'], 'PullRequest'))) - - task: SonarCloudPublish@1 - displayName: Publish SonarCloud analysis results on build summary - condition: and(succeeded(), or(in(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/heads/main'), eq(variables['Build.Reason'], 'PullRequest'))) - inputs: - pollingTimeoutSec: '300' + - task: SonarCloudPublish@1 + displayName: Publish SonarCloud analysis results on build summary + condition: and(succeeded(), or(in(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/heads/main'), eq(variables['Build.Reason'], 'PullRequest'))) + inputs: + pollingTimeoutSec: '300' - - task: CopyFiles@2 - displayName: "Copy Files to: $(build.artifactstagingdirectory)" - inputs: - contents: | - azure/** - targetFolder: "$(build.artifactstagingdirectory)/publish" + - task: CopyFiles@2 + displayName: "Copy Files to: $(build.artifactstagingdirectory)" + inputs: + contents: | + azure/** + targetFolder: "$(build.artifactstagingdirectory)/publish" - - task: PublishBuildArtifacts@1 - displayName: "Publish Artifact" - inputs: - pathtoPublish: "$(build.artifactstagingdirectory)/publish" \ No newline at end of file + - task: PublishBuildArtifacts@1 + displayName: "Publish Artifact" + inputs: + pathtoPublish: "$(build.artifactstagingdirectory)/publish" \ No newline at end of file