Skip to content

Commit

Permalink
feat(jenkins): Add a parameter for an existing analyzer result file
Browse files Browse the repository at this point in the history
This allows to skip the analyzer stage by reusing an existing analyzer
result as a job parameter.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Jan 8, 2024
1 parent 86be29e commit 71e38b9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
42 changes: 42 additions & 0 deletions integrations/jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ pipeline {
* ORT analyzer tool parameters.
*/

stashedFile(
name: 'ANALYZER_RESULT',
description: 'An optional existing analyzer result file to use instead of running the analyzer.'
)

booleanParam(
name: 'ALLOW_DYNAMIC_VERSIONS',
description: 'Allow dynamic versions of dependencies (support projects without lock files).',
Expand Down Expand Up @@ -403,6 +408,35 @@ pipeline {
}
}

stage('Unstash ORT analyzer result') {
agent {
dockerfile {
filename 'Dockerfile-legacy'
additionalBuildArgs DOCKER_BUILD_ARGS + ortVersion
args DOCKER_RUN_ARGS
}
}

when {
beforeAgent true

expression {
env.ANALYZER_RESULT_FILENAME
}
}

steps {
// Note: This unstashes the named file parameter to a file named after the parameter. In particular,
// the original file name is not maintained automatically.
unstash('ANALYZER_RESULT')

sh '''
mkdir -p out/results
ln -frs ANALYZER_RESULT out/results/current-result.yml
'''.stripIndent().trim()
}
}

stage('Run ORT analyzer') {
agent {
dockerfile {
Expand All @@ -412,6 +446,14 @@ pipeline {
}
}

when {
beforeAgent true

expression {
!env.ANALYZER_RESULT_FILENAME
}
}

environment {
HOME = "${env.WORKSPACE}@tmp"
JAVA_OPTS = "-Duser.home=${env.HOME}"
Expand Down
7 changes: 5 additions & 2 deletions integrations/jenkins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ This example allows you to run ORT in a [Jenkins](https://www.jenkins.io/)
## Getting Started

Please follow the regular [installation instructions](https://www.jenkins.io/doc/book/installing/) and additionally
ensure to have the [Pipeline Utility Steps](https://plugins.jenkins.io/pipeline-utility-steps) and
[Docker Pipeline](https://plugins.jenkins.io/docker-workflow) plugins installed.
ensure to have the following Jenkins plugins installed:

* [Docker Pipeline](https://plugins.jenkins.io/docker-workflow)
* [File Parameter](https://plugins.jenkins.io/file-parameters/)
* [Pipeline Utility Steps](https://plugins.jenkins.io/pipeline-utility-steps)

Also ensure that [Docker is installed](https://docs.docker.com/engine/install/) on your system with
[BuildKit enabled](https://docs.docker.com/develop/develop-images/build_enhancements/#to-enable-buildkit-builds), and
Expand Down

0 comments on commit 71e38b9

Please sign in to comment.