-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJenkinsfile
More file actions
146 lines (136 loc) · 6 KB
/
Jenkinsfile
File metadata and controls
146 lines (136 loc) · 6 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
pipeline {
environment {
DOCKER_NETWORK = ''
}
options {
skipDefaultCheckout()
buildDiscarder(logRotator(numToKeepStr: '20'))
timestamps()
}
agent any
stages {
stage('Stop same job builds') {
agent { label 'master' }
steps {
script {
def scmVars = checkout scm
// need this for develop->master PR cases
// CHANGE_BRANCH is not defined if this is a branch build
try {
scmVars.CHANGE_BRANCH_LOCAL = scmVars.CHANGE_BRANCH
}
catch (MissingPropertyException e) {
}
if (scmVars.GIT_LOCAL_BRANCH != "develop" && scmVars.CHANGE_BRANCH_LOCAL != "develop") {
def builds = load ".jenkinsci/cancel-builds-same-job.groovy"
builds.cancelSameJobBuilds()
}
}
}
}
stage('Tests') {
agent { label 'd3-build-agent' }
steps {
script {
def scmVars = checkout scm
tmp = docker.image("gradle:4.10.2-jdk8-slim")
env.WORKSPACE = pwd()
DOCKER_NETWORK = "${scmVars.CHANGE_ID}-${scmVars.GIT_COMMIT}-${BUILD_NUMBER}"
writeFile file: ".env", text: "SUBNET=${DOCKER_NETWORK}"
withCredentials([usernamePassword(credentialsId: 'nexus-soramitsu-ro', usernameVariable: 'login', passwordVariable: 'password')]) {
sh "docker login nexus.iroha.tech:19004 -u ${login} -p '${password}'"
}
withCredentials([usernamePassword(credentialsId: 'nexus-d3-docker', usernameVariable: 'login', passwordVariable: 'password')]) {
sh "docker login nexus.iroha.tech:19002 -u ${login} -p '${password}'"
}
sh "docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.ci.yml pull"
sh(returnStdout: true, script: "docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.ci.yml up --build -d")
iC = docker.image("openjdk:8-jdk")
iC.inside("--network='d3-${DOCKER_NETWORK}' -e JVM_OPTS='-Xmx3200m' -e TERM='dumb' -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp") {
sh "./gradlew dependencies"
sh "./gradlew test --info"
// We need this to test containers
sh "./gradlew eth-withdrawal:shadowJar"
sh "./gradlew dockerfileCreate"
sh "./gradlew compileIntegrationTestKotlin --info"
sh "./gradlew integrationTest --info"
sh "./gradlew d3TestReport"
}
if (env.BRANCH_NAME == 'develop') {
iC.inside("--network='d3-${DOCKER_NETWORK}' -e JVM_OPTS='-Xmx3200m' -e TERM='dumb'") {
withCredentials([string(credentialsId: 'SONAR_TOKEN', variable: 'SONAR_TOKEN')]){
sh(script: "./gradlew sonarqube -x test --configure-on-demand \
-Dsonar.links.ci=${BUILD_URL} \
-Dsonar.github.pullRequest=${env.CHANGE_ID} \
-Dsonar.github.disableInlineComments=true \
-Dsonar.host.url=https://sonar.soramitsu.co.jp \
-Dsonar.login=${SONAR_TOKEN} \
")
}
}
}
publishHTML (target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/reports',
reportFiles: 'd3-test-report.html',
reportName: "D3 test report"])
// scan smartcontracts only on pull requests to master
try {
if (env.CHANGE_TARGET == "master") {
docker.image("mythril/myth").inside("--entrypoint=''") {
sh "echo 'Smart contracts scan results' > mythril.txt"
// using mythril to scan all solidity files
sh "find . -name '*.sol' -exec myth --execution-timeout 900 --create-timeout 900 -x {} \\; | tee mythril.txt"
}
// save results as a build artifact
zip archive: true, dir: '', glob: 'mythril.txt', zipFile: 'smartcontracts-scan-results.zip'
}
}
catch(MissingPropertyException e) { }
}
}
post {
always {
junit allowEmptyResults: true, keepLongStdio: true, testResults: 'build/test-results/**/*.xml'
}
cleanup {
sh "mkdir -p build-logs"
sh """#!/bin/bash
while read -r LINE; do \
docker logs \$(echo \$LINE | cut -d ' ' -f1) | gzip -6 > build-logs/\$(echo \$LINE | cut -d ' ' -f2).log.gz; \
done < <(docker ps --filter "network=d3-${DOCKER_NETWORK}" --format "{{.ID}} {{.Names}}")
"""
sh "tar -zcvf build-logs/notaryEthIntegrationTest.gz -C notary-eth-integration-test/build/reports/tests integrationTest || true"
archiveArtifacts artifacts: 'build-logs/*.gz'
sh "docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.ci.yml down"
cleanWs()
}
}
}
stage('Build and push docker images') {
agent { label 'd3-build-agent' }
steps {
script {
def scmVars = checkout scm
if (env.BRANCH_NAME ==~ /(master|develop|reserved)/ || env.TAG_NAME) {
withCredentials([usernamePassword(credentialsId: 'nexus-d3-docker', usernameVariable: 'login', passwordVariable: 'password')]) {
TAG = env.TAG_NAME ? env.TAG_NAME : env.BRANCH_NAME
iC = docker.image("gradle:4.10.2-jdk8-slim")
iC.inside(" -e JVM_OPTS='-Xmx3200m' -e TERM='dumb'"+
" -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp"+
" -e DOCKER_REGISTRY_URL='https://nexus.iroha.tech:19002'"+
" -e DOCKER_REGISTRY_USERNAME='${login}'"+
" -e DOCKER_REGISTRY_PASSWORD='${password}'"+
" -e TAG='${TAG}'") {
sh "gradle shadowJar"
sh "gradle dockerPush"
}
}
}
}
}
}
}
}