-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
153 lines (143 loc) · 5.24 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
151
152
153
#!groovy
/**
* Jenkins pipeline to build Business Networks Extensions
*/
/**
* Kill already started job.
* Assume new commit takes precendence and results from previous
* unfinished builds are not required.
* This feature doesn't play well with disableConcurrentBuilds() option
*/
@Library('existing-build-control')
import static com.r3.build.BuildControl.killAllExistingBuildsForJob
import com.r3.build.utils.GitUtils
import groovy.transform.Field
killAllExistingBuildsForJob(env.JOB_NAME, env.BUILD_NUMBER.toInteger())
@Field
GitUtils gitUtils = new GitUtils(this)
/**
* Sense environment
*/
boolean isReleaseBranch = (env.BRANCH_NAME =~ /^release\/.*/)
boolean isRelease = (env.TAG_NAME =~ /^release-.*/)
pipeline {
agent {
docker {
// Our custom docker image
image 'build-zulu-openjdk:8'
label 'docker'
registryUrl 'https://engineering-docker.software.r3.com/'
registryCredentialsId 'artifactory-credentials'
// Used to mount storage from the host as a volume to persist the cache between builds
args '-v /tmp:/host_tmp'
alwaysPull true
}
}
parameters {
booleanParam defaultValue: (isReleaseBranch || isRelease), description: 'Publish artifacts to Artifactory?', name: 'DO_PUBLISH'
}
options { timestamps() }
environment {
ARTIFACTORY_CREDENTIALS = credentials('artifactory-credentials')
CORDA_ARTIFACTORY_USERNAME = "${env.CORDA_ARTIFACTORY_USERNAME}"
CORDA_ARTIFACTORY_PASSWORD = "${env.CORDA_ARTIFACTORY_PASSWORD}"
ARTIFACTORY_BUILD_NAME = "DisasterRecovery/Jenkins/${!isRelease?"snapshot/":""}${env.BRANCH_NAME}".replaceAll("/", " :: ")
PUBLISH_REPO = "${isRelease?"corda-releases":"corda-dev"}"
EXECUTOR_NUMBER = "${env.EXECUTOR_NUMBER}"
SNYK_TOKEN = credentials("corda4-os-snyk-secret")
C4_OS_SNYK_ORG_ID = credentials("corda4-os-snyk-org-id")
GRADLE_USER_HOME = "/host_tmp/gradle"
}
stages {
stage('Detekt') {
steps {
sh "./gradlew clean detekt --info"
}
}
stage('Unit Tests') {
steps {
sh "./gradlew clean test --info"
}
}
stage('Integration Tests') {
steps {
sh "./gradlew clean integrationTest --info"
}
}
stage('Snyk Security') {
when {
expression { gitUtils.isReleaseTag() || gitUtils.isReleaseCandidate() || gitUtils.isReleaseBranch() }
}
steps {
script {
def modulesToScan = ['business-networks-contracts', 'business-networks-workflows']
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]+","_")}'", false, true)
}
}
}
}
stage('Generate Snyk License Report') {
options { retry(2) }
when {
expression { gitUtils.isReleaseTag() || gitUtils.isReleaseCandidate() || gitUtils.isReleaseBranch() }
}
steps {
snykLicenseGeneration(env.SNYK_TOKEN, env.C4_OS_SNYK_ORG_ID)
}
post {
always {
script {
archiveArtifacts artifacts: 'snyk-license-report/*-snyk-license-report.html', allowEmptyArchive: true, fingerprint: true
}
}
}
}
stage('Snyk Delta') {
when {
changeRequest()
}
steps {
snykDeltaScan(env.SNYK_TOKEN, env.C4_OS_SNYK_ORG_ID, "--configuration-matching='^runtimeClasspath\$'")
}
}
stage('Publish to Artifactory') {
when {
expression { params.DO_PUBLISH }
beforeAgent true
}
steps {
rtServer(
id: 'R3-Artifactory',
url: 'https://software.r3.com/artifactory',
credentialsId: 'artifactory-credentials'
)
rtGradleDeployer(
id: 'deployer',
serverId: 'R3-Artifactory',
repo: env.PUBLISH_REPO
)
rtGradleRun(
usesPlugin: true,
useWrapper: true,
switches: '-s --info',
tasks: 'artifactoryPublish',
deployerId: 'deployer',
buildName: env.ARTIFACTORY_BUILD_NAME
)
rtPublishBuildInfo(
serverId: 'R3-Artifactory',
buildName: env.ARTIFACTORY_BUILD_NAME
)
}
}
}
post {
always {
junit '**/build/test-results/**/*.xml'
}
cleanup {
deleteDir() /* clean up our workspace */
}
}
}