-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
150 lines (130 loc) · 5.83 KB
/
Jenkinsfile
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
@Library('corda-shared-build-pipeline-steps')
import static com.r3.build.BuildControl.killAllExistingBuildsForJob
killAllExistingBuildsForJob(env.JOB_NAME, env.BUILD_NUMBER.toInteger())
boolean isReleaseBranch = (env.BRANCH_NAME =~ /^release\/.*/)
boolean isRelease = (env.TAG_NAME =~ /^release-.*/)
boolean isOSReleaseBranch = (env.BRANCH_NAME =~ /^release\/os\/.*/)
boolean isEntReleaseBranch = (env.BRANCH_NAME =~ /^release\/ent\/.*/)
boolean isOSReleaseTag = (env.BRANCH_NAME =~ /^release-OS-.*/)
boolean isENTReleaseTag = (env.TAG_NAME =~ /^release-ENT-.*/)
def buildEdition = (isOSReleaseTag) ? "Corda Community Edition" : "Corda Open Source"
String artifactoryBuildName = "Corda-Shell"
// Artifactory build info links
if(!isRelease && isOSReleaseBranch){
artifactoryBuildName = "${artifactoryBuildName}-OS :: Jenkins :: snapshot :: ${env.BRANCH_NAME}"
}else if (isRelease && isOSReleaseTag){
artifactoryBuildName = "${artifactoryBuildName}-OS :: Jenkins :: ${env.BRANCH_NAME}"
}else if(!isRelease && isEntReleaseBranch){
artifactoryBuildName = "${artifactoryBuildName}-Ent :: Jenkins :: snapshot :: ${env.BRANCH_NAME}"
}else if(isRelease && isENTReleaseTag){
artifactoryBuildName = "${artifactoryBuildName}-Ent :: Jenkins :: ${env.BRANCH_NAME}"
}
pipeline {
agent { label 'standard' }
options {
timestamps()
ansiColor('xterm')
overrideIndexTriggers(false)
timeout(time: 1, unit: 'HOURS')
buildDiscarder(logRotator(daysToKeepStr: '14', artifactDaysToKeepStr: '14'))
}
parameters {
booleanParam defaultValue: (isReleaseBranch || isRelease), description: 'Publish artifacts to Artifactory?', name: 'DO_PUBLISH'
}
triggers {
cron (isReleaseBranch ? '@midnight' : '')
}
environment {
ARTIFACTORY_BUILD_NAME = "${artifactoryBuildName}"
ARTIFACTORY_CREDENTIALS = credentials('artifactory-credentials')
CORDA_ARTIFACTORY_USERNAME = "${env.ARTIFACTORY_CREDENTIALS_USR}"
CORDA_ARTIFACTORY_PASSWORD = "${env.ARTIFACTORY_CREDENTIALS_PSW}"
CORDA_BUILD_EDITION = "${buildEdition}"
CORDA_USE_CACHE = "corda-remotes"
SNYK_TOKEN = "c4-os-snyk-shell"
}
stages {
stage('Snyk Security') {
when {
expression { isRelease || isReleaseBranch }
}
steps {
script {
// Invoke Snyk for each Gradle sub project we wish to scan
def modulesToScan = ['standalone-shell', 'shell']
modulesToScan.each { module ->
snykSecurityScan(env.SNYK_TOKEN, "--sub-project=$module --configuration-matching='^runtimeClasspath\$' --prune-repeated-subdependencies --debug --target-reference='${env.BRANCH_NAME}' --project-tags=Branch='${env.BRANCH_NAME.replaceAll("[^0-9|a-z|A-Z]+","_")}'")
}
}
}
}
stage('Build') {
steps {
script{
sh "./gradlew clean assemble -Si"
}
}
}
stage('Test') {
steps {
script{
sh "./gradlew test -Si"
}
}
post {
always {
junit allowEmptyResults: true, testResults: '**/build/test-results/**/TEST-*.xml'
archiveArtifacts artifacts: '**/build/test-results/**/TEST-*.xml', fingerprint: true
}
}
}
stage('Publish to Artifactory') {
when {
expression { params.DO_PUBLISH }
}
steps {
script{
def props = readProperties file: 'gradle.properties'
def groupId = props['cordaReleaseGroup']
boolean isOpenSource = groupId.equals("net.corda") ? true : false
def snapshotRepo
def releasesRepo
if(isOpenSource){
releasesRepo = "corda-releases"
snapshotRepo = "corda-dev"
}else {
releasesRepo = "r3-corda-releases"
snapshotRepo = "r3-corda-dev"
}
rtServer (
id: 'R3-Artifactory',
url: 'https://software.r3.com/artifactory',
credentialsId: 'artifactory-credentials'
)
rtGradleDeployer (
id: 'deployer',
serverId: 'R3-Artifactory',
repo: isRelease ? releasesRepo : snapshotRepo
)
withCredentials([
usernamePassword(credentialsId: 'artifactory-credentials',
usernameVariable: 'CORDA_ARTIFACTORY_USERNAME',
passwordVariable: 'CORDA_ARTIFACTORY_PASSWORD')]) {
rtGradleRun (
usesPlugin: true,
useWrapper: true,
switches: "--no-daemon -Si",
tasks: 'artifactoryPublish',
deployerId: 'deployer',
buildName: env.ARTIFACTORY_BUILD_NAME
)
}
rtPublishBuildInfo (
serverId: 'R3-Artifactory',
buildName: env.ARTIFACTORY_BUILD_NAME
)
}
}
}
}
}