1
- # The name of the build that will be seen in mscodehub
2
- name : PowerShellGetv2-Release-$(Build.BuildId)
3
- # how is the build triggered
4
- # since this is a release build, no trigger as it's a manual release
1
+ name : $(BuildDefinitionName)-$(date:yyMM).$(date:dd)$(rev:rrr)
5
2
trigger : none
3
+ pr : none
6
4
7
- pr :
8
- branches :
9
- include :
10
- - master
11
-
12
- # variables to set in the build environment
13
5
variables :
14
- DOTNET_CLI_TELEMETRY_OPTOUT : 1
15
- POWERSHELL_TELEMETRY_OPTOUT : 1
6
+ - group : ESRP
7
+ - name : ModuleName
8
+ value : ' PowerShellGet'
9
+ - name : BuildOutputPath
10
+ value : ' $(Build.SourcesDirectory)\dist\PowerShellGet'
11
+ - name : SignedOutputPath
12
+ value : ' $(Build.SourcesDirectory)/signed'
16
13
17
- # since this build relies on templates, we need access to those
18
- # This needs a service connection in the build to work
19
- # the *name* of the service connection must be the same as the endpoint
20
14
resources :
21
15
repositories :
22
16
- repository : ComplianceRepo
23
17
type : github
24
18
endpoint : ComplianceGHRepo
25
19
name : PowerShell/compliance
26
- # this can be any branch of your choosing
27
- ref : master
28
20
29
- # the stages in this build. There are 2
30
- # the assumption for PowerShellGetv2 is that test is done as part of
31
- # CI so we needn't do it here
32
21
stages :
33
22
- stage : Build
34
- displayName : Build
35
- pool :
36
- name : Package ES CodeHub Lab E
23
+ displayName : Build PowerShellGetV2 Module Package
37
24
jobs :
38
- - job : Build_Job
39
- displayName : Build Microsoft.PowerShell.PowerShellGetv2
40
- # note the variable reference to ESRP.
41
- # this must be created in Project -> Pipelines -> Library -> VariableGroups
42
- # where it describes the link to the SigningServer
43
- variables :
44
- - group : ESRP
25
+ - job : BuildPkg
26
+ displayName : Build Package
27
+ pool :
28
+ name : 1ES
29
+ demands :
30
+ - ImageOverride -equals PSMMS2019-Secure
31
+
32
+
45
33
steps :
46
- - checkout : self
47
34
48
- # the steps for building the module go here
49
35
- pwsh : |
50
- Set-Location "$(Build.SourcesDirectory)/PowerShellGetv2"
36
+ Get-ChildItem -Path env:
37
+ Get-ChildItem -Path env:
38
+ displayName: Capture environment for build
39
+ condition: succeededOrFailed()
40
+
41
+ - pwsh : |
42
+ Set-Location "$(Build.SourcesDirectory)"
51
43
Import-Module ./tools/build.psm1 -Force
52
44
Install-Dependencies
53
45
Update-ModuleManifestFunctions
54
46
Publish-ModuleArtifacts
55
- displayName: Execute build
47
+ displayName: Build and publish artifact
56
48
57
- # these are setting vso variables which will be persisted between stages
58
49
- pwsh : |
59
- $signSrcPath = "$(Build.SourcesDirectory)/PowerShellGetv2/dist/PowerShellGet"
60
- dir
61
- # Set signing src path variable
50
+ $signSrcPath = "$(BuildOutputPath)"
62
51
$vstsCommandString = "vso[task.setvariable variable=signSrcPath]${signSrcPath}"
63
52
Write-Host "sending " + $vstsCommandString
64
53
Write-Host "##$vstsCommandString"
65
54
66
- $signOutPath = "$(Build.SourcesDirectory)/OSS_Microsoft_PowerShellGetv2/signed/PowerShellGet"
67
- $null = New-Item -ItemType Directory -Path $signOutPath -force
68
- # Set signing out path variable
69
- $vstsCommandString = "vso[task.setvariable variable=signOutPath]${signOutPath}"
55
+ $outSignPath = "$(BuildOutputPath)"
56
+ $vstsCommandString = "vso[task.setvariable variable=signOutPath]${outSignPath}"
70
57
Write-Host "sending " + $vstsCommandString
71
58
Write-Host "##$vstsCommandString"
59
+ displayName: Create fake source and output variables for signing template and no signing
60
+ condition: and(succeeded(), eq(variables['SkipSigning'], 'True'))
61
+
62
+ - pwsh : |
63
+ $env:PSModulePath = $modulePath + [System.IO.Path]::PathSeparator + $env:PSModulePath
64
+
65
+ # Created files signing directory
66
+ $srcPath = "$(BuildOutputPath)"
67
+ $createdSignSrcPath = "$(SignedOutputPath)\CreatedFiles"
68
+ if (! (Test-Path -Path $createdSignSrcPath)) {
69
+ $null = New-Item -Path $createdSignSrcPath -ItemType Directory -Verbose
70
+ }
71
+ Copy-Item -Path $srcPath -Dest $createdSignSrcPath -Recurse -Force -Verbose
72
72
73
- # Set path variable for guardian codesign validation
74
- $vstsCommandString = "vso[task.setvariable variable=GDN_CODESIGN_TARGETDIRECTORY]${signOutPath}"
73
+ $signOutPath = "$(SignedOutputPath)\$(ModuleName)"
74
+ if (! (Test-Path -Path $signOutPath)) {
75
+ $null = New-Item -Path $signOutPath -ItemType Directory
76
+ }
77
+
78
+ # Set signing src path variable
79
+ $vstsCommandString = "vso[task.setvariable variable=signSrcPath]${createdSignSrcPath}"
75
80
Write-Host "sending " + $vstsCommandString
76
81
Write-Host "##$vstsCommandString"
77
82
78
- # Get version and create a variable
79
- $moduleData = Import-PowerShellDataFile "$(Build.SourcesDirectory)/PowerShellGetv2/dist/PowerShellGet/PowerShellGet.psd1"
80
- $moduleVersion = $moduleData.ModuleVersion
81
- $vstsCommandString = "vso[task.setvariable variable=moduleVersion]${moduleVersion}"
83
+ $outSignPath = "$(SignedOutputPath)\$(ModuleName)"
84
+ if (! (Test-Path -Path $outSignPath)) {
85
+ $null = New-Item -Path $outSignPath -ItemType Directory -Verbose
86
+ }
87
+
88
+ # Set signing out path variable
89
+ $vstsCommandString = "vso[task.setvariable variable=signOutPath]${outSignPath}"
82
90
Write-Host "sending " + $vstsCommandString
83
91
Write-Host "##$vstsCommandString"
84
- displayName: Setup variables for signing
92
+ displayName: Set up for module created files code signing
93
+ condition: and(and(succeeded(), eq(variables['Build.Reason'], 'Manual')), ne(variables['SkipSigning'], 'True'))
85
94
86
- # checkout the Compliance repository so it can be used to do the actual signing
87
- - checkout : ComplianceRepo
95
+ - pwsh : |
96
+ Get-ChildItem -Path env:
97
+ Get-ChildItem -Path . -Recurse -Directory
98
+ displayName: Capture environment for code signing
99
+ condition: succeededOrFailed()
88
100
89
- # this the MS authored step This cert covers MS autored items
90
- # note that the buildOutputPath (where we get the files to sign)
91
- # is the same as the signOutputPath in the previous step
92
- # at the end of this step we will have all the files signed that should be
93
- # signOutPath is the location which contains the files we will use to make the module
94
101
- template : EsrpSign.yml@ComplianceRepo
95
102
parameters :
96
- # the folder which contains the binaries to sign
97
103
buildOutputPath : $(signSrcPath)
98
- # the location to put the signed output
99
104
signOutputPath : $(signOutPath)
100
- # the certificate ID to use (Authenticode)
101
105
certificateId : " CP-230012"
102
106
pattern : |
103
107
**\*.psd1
104
108
**\*.psm1
105
109
**\*.ps1xml
106
110
**\*.mof
111
+ useMinimatch : true
112
+
113
+ - pwsh : |
114
+ $srcPath = "$(BuildOutputPath)"
115
+ $signOutPath = "$(SignedOutputPath)\$(ModuleName)"
116
+ if (! (Test-Path -Path $signOutPath)) {
117
+ $null = New-Item -Path $signOutPath -ItemType Directory
118
+ }
119
+
120
+ Get-ChildItem -Path $srcPath | Foreach-Object {
121
+ if ($_.Attributes -ne "Directory")
122
+ {
123
+ $sig = Get-AuthenticodeSignature -FilePath $_.FullName
124
+ if ($sig.Status -eq 'Valid' -and ($sig.SignerCertificate.Subject -like '*Microsoft*' -and $sig.SignerCertificate.Issuer -like '*Microsoft Code Signing PCA*')) {
125
+ # Copy already signed files directly to output
126
+ Copy-Item -Path $_.FullName -Dest $signOutPath -Force -Verbose
127
+ }
128
+ }
129
+ }
130
+ displayName: Copy already properly signed files (.psd1, .psm1, .ps1xml, .mof)
131
+ condition: and(and(succeeded(), eq(variables['Build.Reason'], 'Manual')), ne(variables['SkipSigning'], 'True'))
132
+
133
+ - ${{ if ne(variables.SkipSigning, 'True') }} :
134
+ - template : Sbom.yml@ComplianceRepo
135
+ parameters :
136
+ BuildDropPath : $(signOutPath)
137
+ Build_Repository_Uri : ' https://github.com/powershell/powershellgetv2'
138
+ PackageName : ' PowerShellGet'
139
+ PackageVersion : ' 2.2.5.1'
140
+
141
+ - pwsh : |
142
+ $srcModulePath = Resolve-Path -Path "$(signOutPath)" # build drop path -- '$(Build.SourcesDirectory)/signed/PowerShellGet'
143
+ $nupkgPath = "$(SignedOutputPath)/nupkg" # '$(Build.SourcesDirectory)/signed/nupkg'
144
+ $tmpPkgMgmtDir = "$(SignedOutputPath)/tmpDir" # '$(Build.SourcesDirectory)/signed/tmpDir'
145
+ mkdir $nupkgPath
146
+ mkdir $tmpPkgMgmtDir
107
147
108
- # finally publish the parts of the build which will be used in the next stages
109
- # if it's not published, the subsequent stages will not be able to access it.
110
- # This is the build directory (it contains all of the dll/pdb files)
111
- - publish : " $(Build.SourcesDirectory)/OSS_Microsoft_PowerShellGetv2"
112
- artifact : build
113
- displayName : publish build directory
148
+ $srcLocation = [System.Uri] $nupkgPath.ToString()
149
+ Register-PSRepository -Name "LocalNupkgRepo" -SourceLocation $srcLocation # '$(Build.SourcesDirectory)/signed/nupkg'
150
+ $moduleToPublish = Join-Path -Path $srcModulePath -ChildPath "PowerShellGet" # '$(Build.SourcesDirectory)/signed/PowerShellGet/PowerShellGet'
151
+
152
+ Save-Module -Name PackageManagement -Repository PSGallery -Path $tmpPkgMgmtDir ## '$(Build.SourcesDirectory)/signed/tmpDir'
153
+ Publish-Module -Path (Join-Path -Path $tmpPkgMgmtDir -ChildPath "PackageManagement") -Repository "LocalNupkgRepo" # '$(Build.SourcesDirectory)/signed/nupkg'
154
+
155
+ Publish-Module -Path $moduleToPublish -Repository "LocalNupkgRepo" # '$(Build.SourcesDirectory)/signed/nupkg'
156
+
157
+ Remove-Item $nupkgPath/PackageManagement*.nupkg
158
+ $artifactName = "$(ModuleName)"
159
+ $nupkgName = "nupkg"
160
+ Write-Host "##vso[artifact.upload containerfolder=$artifactName;artifactname=$nupkgName;]$nupkgPath"
161
+ Write-Host "##vso[artifact.upload containerfolder=$artifactName;artifactname=$artifactName;]$srcModulePath"
162
+ displayName: Create module artifacts (including .nupkg)
114
163
115
164
# Now on to the compliance stage
116
165
- stage : compliance
117
166
displayName : Compliance
118
167
dependsOn : Build
119
168
jobs :
120
- - job : Compliance_Job
169
+ - job : ComplianceJob
121
170
pool :
122
- name : Package ES CodeHub Lab E
171
+ name : 1ES
172
+ demands :
173
+ - ImageOverride -equals PSMMS2019-Secure
174
+
123
175
steps :
124
176
- checkout : self
177
+ clean : true
125
178
- checkout : ComplianceRepo
179
+ clean : true
126
180
- download : current
127
- artifact : build
128
-
129
- # use the templates in the compliance repo
130
- # since script analyzer has modules, we're using the assembly-module-compliance template
131
- # if you don't have assemblies, you should use script-module-compliance template
181
+ artifact : ' PowerShellGet'
132
182
- template : script-module-compliance.yml@ComplianceRepo
133
183
parameters :
134
184
# component-governance - the path to sources
135
185
sourceScanPath : ' $(Build.SourcesDirectory)'
186
+ # credscan
187
+ suppressionsFile : ' '
136
188
# TermCheck
137
189
optionsRulesDBPath : ' '
138
190
optionsFTPath : ' '
@@ -141,3 +193,9 @@ stages:
141
193
codeBaseName : ' PowerShellGetv2_20200129'
142
194
# selections
143
195
APIScan : false # set to false when not using Windows APIs.
196
+
197
+ - stage : Release
198
+ displayName : Publish Package to PSGallery
199
+ condition : and(and(succeeded(), eq(variables['Build.Reason'], 'Manual')), eq(variables['Publish'], 'True'))
200
+ jobs :
201
+ - template : release.yml
0 commit comments