Skip to content

Commit 6027e96

Browse files
committed
Rewrite the Jenkinsfile to use Docker stages with the multi-stage file
The main advantage over calling Docker manually is that Jenkins takes care of properly mounting the workspace. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 0b64003 commit 6027e96

File tree

2 files changed

+68
-17
lines changed

2 files changed

+68
-17
lines changed

.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
.dockerignore
44
Dockerfile
55

6+
# Ignore the Jenkinsfile to avoid that all layers are invalidated if the
7+
# Jenkinsfile is changed during development.
8+
Jenkinsfile
9+
610
# Ignore the Git directory.
711
.git/
812

Jenkinsfile

+64-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019 Bosch Software Innovations GmbH
2+
* Copyright (C) 2020 Bosch.IO GmbH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,8 +17,13 @@
1717
* License-Filename: LICENSE
1818
*/
1919

20+
final DOCKER_BUILD_ARGS = '--build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy'
21+
22+
// Disable the entry point to work around https://issues.jenkins-ci.org/browse/JENKINS-51307.
23+
final DOCKER_RUN_ARGS = '-e http_proxy -e https_proxy --entrypoint=""'
24+
2025
pipeline {
21-
agent any
26+
agent none
2227

2328
parameters {
2429
string(
@@ -54,25 +59,38 @@ pipeline {
5459

5560
stages {
5661
stage('Clone project') {
62+
agent any
63+
64+
environment {
65+
HOME = "${env.WORKSPACE}@tmp"
66+
PROJECT_DIR = "${env.HOME}/project"
67+
}
68+
5769
steps {
58-
sh 'rm -fr project'
70+
sh 'rm -fr $PROJECT_DIR'
5971

6072
// See https://jenkins.io/doc/pipeline/steps/git/.
6173
checkout([$class: 'GitSCM',
6274
userRemoteConfigs: [[url: params.VCS_URL]],
6375
branches: [[name: "${params.VCS_REVISION}"]],
64-
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'project/source']]
76+
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: "${env.PROJECT_DIR}/source"]]
6577
])
6678
}
6779
}
6880

69-
stage('Build ORT distribution') {
70-
steps {
71-
sh 'docker/build.sh'
81+
stage('Run the ORT analyzer') {
82+
agent {
83+
dockerfile {
84+
additionalBuildArgs DOCKER_BUILD_ARGS
85+
args DOCKER_RUN_ARGS
86+
}
87+
}
88+
89+
environment {
90+
HOME = "${env.WORKSPACE}@tmp"
91+
PROJECT_DIR = "${env.HOME}/project"
7292
}
73-
}
7493

75-
stage('Run ORT analyzer') {
7694
steps {
7795
sh '''
7896
if [ "$ALLOW_DYNAMIC_VERSIONS" = "true" ]; then
@@ -83,44 +101,73 @@ pipeline {
83101
USE_CLEARLY_DEFINED_CURATIONS_PARAM="--clearly-defined-curations"
84102
fi
85103
86-
docker/run.sh "-v $WORKSPACE/project:/project" $LOG_LEVEL analyze $ALLOW_DYNAMIC_VERSIONS_PARAM $USE_CLEARLY_DEFINED_CURATIONS_PARAM -f JSON,YAML -i /project/source -o /project/ort/analyzer
104+
rm -fr analyzer/out/results
105+
/opt/ort/bin/ort $LOG_LEVEL analyze $ALLOW_DYNAMIC_VERSIONS_PARAM $USE_CLEARLY_DEFINED_CURATIONS_PARAM -f JSON,YAML -i $PROJECT_DIR/source -o analyzer/out/results
87106
'''
88107
}
89108

90109
post {
91110
always {
92111
archiveArtifacts(
93-
artifacts: 'project/ort/analyzer/*',
112+
artifacts: 'analyzer/out/results/*',
94113
fingerprint: true
95114
)
96115
}
97116
}
98117
}
99118

100-
stage('Run ORT scanner') {
119+
stage('Run the ORT scanner') {
120+
agent {
121+
dockerfile {
122+
additionalBuildArgs DOCKER_BUILD_ARGS
123+
args DOCKER_RUN_ARGS
124+
}
125+
}
126+
127+
environment {
128+
HOME = "${env.WORKSPACE}@tmp"
129+
}
130+
101131
steps {
102-
sh 'docker/run.sh "-v $WORKSPACE/project:/project" $LOG_LEVEL scan -f JSON,YAML -i /project/ort/analyzer/analyzer-result.yml -o /project/ort/scanner'
132+
sh '''
133+
rm -fr scanner/out/results
134+
/opt/ort/bin/ort $LOG_LEVEL scan -f JSON,YAML -i analyzer/out/results/analyzer-result.yml -o scanner/out/results
135+
'''
103136
}
104137

105138
post {
106139
always {
107140
archiveArtifacts(
108-
artifacts: 'project/ort/scanner/*',
141+
artifacts: 'scanner/out/results/*',
109142
fingerprint: true
110143
)
111144
}
112145
}
113146
}
114147

115-
stage('Run ORT reporter') {
148+
stage('Run the ORT reporter') {
149+
agent {
150+
dockerfile {
151+
additionalBuildArgs DOCKER_BUILD_ARGS
152+
args DOCKER_RUN_ARGS
153+
}
154+
}
155+
156+
environment {
157+
HOME = "${env.WORKSPACE}@tmp"
158+
}
159+
116160
steps {
117-
sh 'docker/run.sh "-v $WORKSPACE/project:/project" $LOG_LEVEL report -f CycloneDX,NoticeByPackage,NoticeSummary,StaticHTML,WebApp -i /project/ort/scanner/scan-result.yml -o /project/ort/reporter'
161+
sh '''
162+
rm -fr reporter/out/results
163+
/opt/ort/bin/ort $LOG_LEVEL report -f CycloneDX,NoticeByPackage,NoticeSummary,StaticHTML,WebApp -i scanner/out/results/scan-result.yml -o reporter/out/results
164+
'''
118165
}
119166

120167
post {
121168
always {
122169
archiveArtifacts(
123-
artifacts: 'project/ort/reporter/*',
170+
artifacts: 'reporter/out/results/*',
124171
fingerprint: true
125172
)
126173
}

0 commit comments

Comments
 (0)