|
| 1 | +# The name of the build that will be seen in mscodehub |
| 2 | +name: PSSA-Release-$(Build.BuildId) |
| 3 | +# how is the build triggered |
| 4 | +# since this is a release build, no trigger as it's a manual release |
| 5 | +trigger: none |
| 6 | + |
| 7 | +pr: |
| 8 | + branches: |
| 9 | + include: |
| 10 | + - master |
| 11 | + - release* |
| 12 | + |
| 13 | +# variables to set in the build environment |
| 14 | +variables: |
| 15 | + DOTNET_CLI_TELEMETRY_OPTOUT: 1 |
| 16 | + POWERSHELL_TELEMETRY_OPTOUT: 1 |
| 17 | + |
| 18 | +# since this build relies on templates, we need access to those |
| 19 | +# This needs a service connection in the build to work |
| 20 | +# the *name* of the service connection must be the same as the endpoint |
| 21 | +resources: |
| 22 | + repositories: |
| 23 | + - repository: ComplianceRepo |
| 24 | + type: github |
| 25 | + endpoint: ComplianceGHRepo |
| 26 | + name: PowerShell/compliance |
| 27 | + # this can be any branch of your choosing |
| 28 | + ref: master |
| 29 | + |
| 30 | +# the stages in this build. There are 2 |
| 31 | +# the assumption for script analyzer is that test is done as part of |
| 32 | +# CI so we needn't do it here |
| 33 | +stages: |
| 34 | +- stage: Build |
| 35 | + displayName: Build |
| 36 | + pool: |
| 37 | + name: Package ES CodeHub Lab E |
| 38 | + jobs: |
| 39 | + - job: Build_Job |
| 40 | + displayName: Build Microsoft.PowerShell.ScriptAnalyzer |
| 41 | + # note the variable reference to ESRP. |
| 42 | + # this must be created in Project -> Pipelines -> Library -> VariableGroups |
| 43 | + # where it describes the link to the SigningServer |
| 44 | + variables: |
| 45 | + - group: ESRP |
| 46 | + steps: |
| 47 | + - checkout: self |
| 48 | + |
| 49 | + # the steps for building the module go here |
| 50 | + - pwsh: | |
| 51 | + Set-Location "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA" |
| 52 | + try { ./build.ps1 -Configuration Release -All } catch { throw $_ } |
| 53 | + displayName: Execute build |
| 54 | +
|
| 55 | + # these are setting vso variables which will be persisted between stages |
| 56 | + - pwsh: | |
| 57 | + $signSrcPath = "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA/out" |
| 58 | + # Set signing src path variable |
| 59 | + $vstsCommandString = "vso[task.setvariable variable=signSrcPath]${signSrcPath}" |
| 60 | + Write-Host "sending $vstsCommandString" |
| 61 | + Write-Host "##$vstsCommandString" |
| 62 | +
|
| 63 | + $signOutStep1 = "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA/Step1" |
| 64 | + $null = New-Item -ItemType Directory -Path $signOutStep1 |
| 65 | + # Set signing out path variable |
| 66 | + $vstsCommandString = "vso[task.setvariable variable=signOutStep1]${signOutStep1}" |
| 67 | + Write-Host "sending $vstsCommandString" |
| 68 | + Write-Host "##$vstsCommandString" |
| 69 | +
|
| 70 | + $signOutPath = "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA/signed" |
| 71 | + $null = New-Item -ItemType Directory -Path $signOutPath |
| 72 | + # Set signing out path variable |
| 73 | + $vstsCommandString = "vso[task.setvariable variable=signOutPath]${signOutPath}" |
| 74 | + Write-Host "sending $vstsCommandString" |
| 75 | + Write-Host "##$vstsCommandString" |
| 76 | +
|
| 77 | + # Set path variable for guardian codesign validation |
| 78 | + $vstsCommandString = "vso[task.setvariable variable=GDN_CODESIGN_TARGETDIRECTORY]${signOutPath}" |
| 79 | + Write-Host "sending $vstsCommandString" |
| 80 | + Write-Host "##$vstsCommandString" |
| 81 | +
|
| 82 | + # Get version and create a variable |
| 83 | + $moduleData = Import-PowerShellDataFile "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA/Engine/PSScriptAnalyzer.psd1" |
| 84 | + $moduleVersion = $moduleData.ModuleVersion |
| 85 | + $vstsCommandString = "vso[task.setvariable variable=moduleVersion]${moduleVersion}" |
| 86 | + Write-Host "sending $vstsCommandString" |
| 87 | + Write-Host "##$vstsCommandString" |
| 88 | +
|
| 89 | +
|
| 90 | + displayName: Setup variables for signing |
| 91 | +
|
| 92 | + # checkout the Compliance repository so it can be used to do the actual signing |
| 93 | + - checkout: ComplianceRepo |
| 94 | + |
| 95 | + # in script analyzer, we must sign with 2 different certs |
| 96 | + # the normal cert for MS created items and the 3rd party cert |
| 97 | + # this the MS authored step |
| 98 | + # Because this needs 2 certs, we do it in 2 steps. |
| 99 | + # the first step signs the binaries and puts them in a staging directory which |
| 100 | + # will then be used for the second step. |
| 101 | + - template: EsrpSign.yml@ComplianceRepo |
| 102 | + parameters: |
| 103 | + # the folder which contains the binaries to sign |
| 104 | + buildOutputPath: $(signSrcPath) |
| 105 | + # the location to put the signed output |
| 106 | + signOutputPath: $(signOutStep1) |
| 107 | + # the certificate ID to use |
| 108 | + certificateId: "CP-230012" |
| 109 | + # use minimatch because we need to exclude the NewtonSoft assembly |
| 110 | + useMinimatch: true |
| 111 | + # the file pattern to use - newtonSoft is excluded |
| 112 | + pattern: | |
| 113 | + **\*.psd1 |
| 114 | + **\*.psm1 |
| 115 | + **\*.ps1xml |
| 116 | + **\Microsoft*.dll |
| 117 | +
|
| 118 | + # this is the second step of the signing. |
| 119 | + # note that the buildOutputPath (where we get the files to sign) |
| 120 | + # is the same as the signOutputPath in the previous step |
| 121 | + # at the end of this step we will have all the files signed that should be |
| 122 | + # signOutPath is the location which contains the files we will use to make the module |
| 123 | + - template: EsrpSign.yml@ComplianceRepo |
| 124 | + parameters: |
| 125 | + # the folder which contains the binaries to sign |
| 126 | + buildOutputPath: $(signOutStep1) |
| 127 | + # the location to put the signed output |
| 128 | + signOutputPath: $(signOutPath) |
| 129 | + # the certificate ID to use |
| 130 | + # we'll need to change this to the 3rd party cert id |
| 131 | + certificateId: "CP-231522" |
| 132 | + # the file pattern to use - only sign newtonsoft |
| 133 | + pattern: 'Newtonsoft*.dll' |
| 134 | + |
| 135 | + # now create the nupkg which we will use to publish the module |
| 136 | + # to the powershell gallery (not part of this yaml) |
| 137 | + - pwsh: | |
| 138 | + Set-Location "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA" |
| 139 | + ./build -BuildNupkg -signed |
| 140 | + displayName: Create nupkg for publishing |
| 141 | +
|
| 142 | + # finally publish the parts of the build which will be used in the next stages |
| 143 | + # if it's not published, the subsequent stages will not be able to access it. |
| 144 | + # This is the build directory (it contains all of the dll/pdb files) |
| 145 | + - publish: "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA" |
| 146 | + artifact: build |
| 147 | + displayName: publish build directory |
| 148 | + |
| 149 | + # export the nupkg only which will be used in the release pipeline |
| 150 | + - publish: "$(signOutPath)/PSScriptAnalyzer.$(moduleVersion).nupkg" |
| 151 | + artifact: nupkg |
| 152 | + displayName: Publish module nupkg |
| 153 | + |
| 154 | +# Now on to the compliance stage |
| 155 | +- stage: compliance |
| 156 | + displayName: Compliance |
| 157 | + dependsOn: Build |
| 158 | + jobs: |
| 159 | + - job: Compliance_Job |
| 160 | + pool: |
| 161 | + name: Package ES CodeHub Lab E |
| 162 | + steps: |
| 163 | + - checkout: self |
| 164 | + - checkout: ComplianceRepo |
| 165 | + - download: current |
| 166 | + artifact: build |
| 167 | + |
| 168 | + # use the templates in the compliance repo |
| 169 | + # since script analyzer has modules, we're using the assembly-module-compliance template |
| 170 | + # if you don't have assemblies, you should use script-module-compliance template |
| 171 | + - template: assembly-module-compliance.yml@ComplianceRepo |
| 172 | + parameters: |
| 173 | + # component-governance - the path to sources |
| 174 | + sourceScanPath: '$(Build.SourcesDirectory)/OSS_Microsoft_PSSA' |
| 175 | + # binskim - this isn't recursive, so you need the path to the assemblies |
| 176 | + AnalyzeTarget: '$(Pipeline.Workspace)\build\bin\PSV7Release\netcoreapp3.1\*.dll' |
| 177 | + # credscan - scan the repo for credentials |
| 178 | + # you can suppress some files with this. |
| 179 | + suppressionsFile: '$(Build.SourcesDirectory)/OSS_Microsoft_PSSA/tools/ReleaseBuild/CredScan.Suppressions.json' |
| 180 | + # TermCheck |
| 181 | + optionsRulesDBPath: '' |
| 182 | + optionsFTPath: '' |
| 183 | + # tsa-upload |
| 184 | + # the compliance scanning must be uploaded, which you need to request |
| 185 | + codeBaseName: 'PSSA_202004' |
| 186 | + # selections |
| 187 | + APIScan: false # set to false when not using Windows APIs. |
| 188 | + |
| 189 | +#- template: template/publish.yml |
| 190 | +# parameters: |
| 191 | +# stageName: AzArtifactsFeed |
| 192 | +# environmentName: |
| 193 | +# feedCredential: |
| 194 | + |
| 195 | +#- template: template/publish.yml |
| 196 | +# parameters: |
| 197 | +# stageName: NuGet |
| 198 | +# environmentName: PSMarkdownRenderNuGetApproval |
| 199 | +# feedCredential: NugetOrgPush |
0 commit comments