-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
131 lines (113 loc) · 4.77 KB
/
Jenkinsfile
File metadata and controls
131 lines (113 loc) · 4.77 KB
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
@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 isReleaseTag = (env.TAG_NAME =~ /^release-.*/)
boolean isRelease = isReleaseTag
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 publishOptions = (isRelease || isReleaseBranch) ? "-s --info" : "--no-daemon -s -PversionFromGit"
String artifactoryBuildName = "Corda-Shell"
// Artifactory build info links
if(!isReleaseTag && isOSReleaseBranch){
artifactoryBuildName = "${artifactoryBuildName}-OS :: Jenkins :: snapshot :: ${env.BRANCH_NAME}"
}else if (isReleaseTag && isOSReleaseTag){
artifactoryBuildName = "${artifactoryBuildName}-OS :: Jenkins :: ${env.BRANCH_NAME}"
}else if(!isReleaseTag && isEntReleaseBranch){
artifactoryBuildName = "${artifactoryBuildName}-Ent :: Jenkins :: snapshot :: ${env.BRANCH_NAME}"
}else if(isReleaseTag && isENTReleaseTag){
artifactoryBuildName = "${artifactoryBuildName}-Ent :: Jenkins :: ${env.BRANCH_NAME}"
}
pipeline {
agent { label 'standard' }
options {
timestamps()
ansiColor('xterm')
timeout(time: 1, unit: 'HOURS')
buildDiscarder(logRotator(daysToKeepStr: '14', artifactDaysToKeepStr: '14'))
}
parameters {
booleanParam defaultValue: isRelease || isReleaseBranch, 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"
JAVA_HOME="/usr/lib/jvm/java-17-amazon-corretto"
}
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 integrationTest -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 {
rtServer(
id: 'R3-Artifactory',
url: 'https://software.r3.com/artifactory',
credentialsId: 'artifactory-credentials'
)
rtGradleDeployer(
id: 'deployer',
serverId: 'R3-Artifactory',
repo: isRelease ? 'corda-releases' : 'corda-dev'
)
rtGradleRun(
usesPlugin: true,
useWrapper: true,
switches: publishOptions,
tasks: 'artifactoryPublish',
deployerId: 'deployer',
buildName: env.ARTIFACTORY_BUILD_NAME
)
rtPublishBuildInfo(
serverId: 'R3-Artifactory',
buildName: env.ARTIFACTORY_BUILD_NAME
)
}
}
}
}