-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathazure-pipelines.yml
167 lines (148 loc) · 6.36 KB
/
azure-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/java
trigger:
branches:
include: [ master, release-* ]
pool:
vmImage: 'ubuntu-latest'
# Maven Build Variables:
variables:
version: '7.5.0.$(Build.BuildId)-SNAPSHOT'
targetDir: 'target'
codeSigningCertFileName: 'OneIdentityCodeSigning.pfx'
issuerKeyStorePath: 'settings/signingstore.jks'
gpgKeyName: '[email protected]'
isPrerelease: ${{ true }}
isReleaseBranch: $[ or( eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release-') ) ]
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: 'env | sort'
displayName: 'Display environment variables'
- task: AzureKeyVault@1
inputs:
azureSubscription: 'OneIdentity.RD.SBox.Safeguard-ServiceConnection'
keyVaultName: 'SafeguardBuildSecrets'
secretsFilter: '*'
displayName: 'Get Sonatype password from Sandbox Azure Key Vault'
condition: and(succeeded(), eq(variables.isReleaseBranch, true))
- task: AzureKeyVault@1
inputs:
azureSubscription: 'Azure.Infrastructure.CodeSigning'
KeyVaultName: 'CodeSigningCertificates'
SecretsFilter: '*'
displayName: 'Get code signing certificate from Azure Key Vault'
condition: and(succeeded(), eq(variables.isReleaseBranch, true))
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$kvSecretBytes = [System.Convert]::FromBase64String("$(OneIdentity-CodeSigning)")
$certCollection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection
$certCollection.Import($kvSecretBytes,$null,[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$protectedCertificateBytes = $certCollection.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12,"$(OneIdentity-CodeSigningCertPassword)")
$certpath = '$(Build.BinariesDirectory)/$(codeSigningCertFileName)'
Write-Verbose -Verbose $certpath
[System.IO.File]::WriteAllBytes($certpath, $protectedCertificateBytes)
displayName: 'Save code signing certificate to PFX file'
condition: and(succeeded(), eq(variables.isReleaseBranch, true))
- task: Bash@3
inputs:
targetType: 'inline'
script: 'keytool -v -importkeystore -destkeystore $(Build.BinariesDirectory)/$(codeSigningCertFileName) -deststoretype PKCS12 -deststorepass $(OneIdentity-CodeSigningCertPassword) -srckeystore $(Build.SourcesDirectory)/$(issuerKeyStorePath) -srcstoretype PKCS12 -srcstorepass $(SigningStorePassword)'
displayName: 'Create the signing keystore'
condition: and(succeeded(), eq(variables.isReleaseBranch, true))
- script: echo ${SIGNINGGKEY} > $(Build.BinariesDirectory)/signingkey.org
env:
SIGNINGGKEY: $(GpgCodeSigningKey)
displayName: 'Save signing key'
condition: and(succeeded(), eq(variables.isReleaseBranch, true))
- task: Bash@3
inputs:
targetType: 'inline'
script: |
export GPG_TTY=$(tty)
sed 's/\\n/\n/g' $(Build.BinariesDirectory)/signingkey.org > $(Build.BinariesDirectory)/signingkey.asc
gpg --batch --import $(Build.BinariesDirectory)/signingkey.asc
displayName: 'Import the signing key'
condition: and(succeeded(), eq(variables.isReleaseBranch, true))
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
Options: '-X -Drevision=$(version)'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'package'
displayName: 'Build and package SafeguardJava $(version)'
condition: and(succeeded(), eq(variables.isReleaseBranch, false))
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
Options: '-X --settings $(Build.SourcesDirectory)/settings/settings.xml -P release -D sonatypeusername=$(SonatypeUserToken) -D sonatypepassword=$(SonatypeRepositoryPassword) -D revision=$(version) -D signingcertpath=$(Build.BinariesDirectory)/$(codeSigningCertFileName) -D signingcertaliasname=1 -D signingcertpassword=$(OneIdentity-CodeSigningCertPassword) -D signingkeystorepassword=$(SigningStorePassword) -D gpgkeyname=$(gpgKeyName)'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'deploy'
displayName: 'Build and deploy SafeguardJava $(version)'
condition: and(succeeded(), eq(variables.isReleaseBranch, true))
- task: DeleteFiles@1
inputs:
SourceFolder: '$(Build.BinariesDirectory)'
Contents: '$(codeSigningCertFileName)'
condition: succeededOrFailed()
displayName: 'Delete code signing certificate files'
- task: CopyFiles@2
inputs:
sourceFolder: '$(Build.SourcesDirectory)/$(targetDir)'
contents: '*.jar'
targetFolder: $(Build.ArtifactStagingDirectory)
displayName: 'Copy files to staging folder'
- task: CopyFiles@2
inputs:
sourceFolder: '$(Build.SourcesDirectory)/$(targetDir)'
contents: '*.asc'
targetFolder: $(Build.ArtifactStagingDirectory)
displayName: 'Copy files to staging folder'
- task: CopyFiles@2
inputs:
sourceFolder: '$(Build.SourcesDirectory)/$(targetDir)'
contents: '**/lib/**'
targetFolder: $(Build.ArtifactStagingDirectory)
displayName: 'Copy files to staging folder'
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'SafeguardJava'
displayName: 'Publishing the artifacts'
- task: Bash@3
inputs:
targetType: 'inline'
script: 'ls $(Build.ArtifactStagingDirectory)'
displayName: 'List staging directory'
- task: GitHubRelease@1
inputs:
gitHubConnection: 'PangaeaBuild-GitHub'
repositoryName: 'OneIdentity/SafeguardJava'
action: 'create'
target: '$(Build.SourceVersion)'
tagSource: 'userSpecifiedTag'
tag: 'release-$(version)'
title: '$(version)'
isPreRelease: $(isPrerelease)
changeLogCompareToRelease: 'lastFullRelease'
changeLogType: 'commitBased'
assets: |
$(Build.ArtifactStagingDirectory)/*.jar
$(Build.ArtifactStagingDirectory)/*.asc
displayName: 'Creating and publishing a release to Github'
condition: and(succeeded(), eq(variables.isReleaseBranch, true))