From ca6dc0e23f52546902a955c8df7ef9197d0215c4 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 29 Nov 2023 13:38:32 +0100 Subject: [PATCH] feat(jenkins): Allow to set arbitrary environment variables This is useful when referring to environment variables in a `config.yml` template, like API keys. Signed-off-by: Sebastian Schuberth --- integrations/jenkins/Jenkinsfile | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/integrations/jenkins/Jenkinsfile b/integrations/jenkins/Jenkinsfile index 9e8900dd80094..18e9ca9c9a903 100644 --- a/integrations/jenkins/Jenkinsfile +++ b/integrations/jenkins/Jenkinsfile @@ -96,6 +96,12 @@ pipeline { defaultValue: '' ) + string( + name: 'ENVIRONMENT_VARIABLES', + description: 'Optional list of comma-separated key=value pairs of environment variables to set.', + defaultValue: '' + ) + choice( name: 'LOG_LEVEL', description: 'The logging level.', @@ -387,6 +393,13 @@ pipeline { } steps { + script { + params.ENVIRONMENT_VARIABLES.tokenize(',').each { + def (key, value) = it.split('=', limit = 2) + env."${key.trim()}" = value.trim() + } + } + script { def status = sh returnStatus: true, script: ''' ORT_OPTIONS="$LOG_LEVEL -P ort.analyzer.allowDynamicVersions=$ALLOW_DYNAMIC_VERSIONS" @@ -468,6 +481,13 @@ pipeline { } steps { + script { + params.ENVIRONMENT_VARIABLES.tokenize(',').each { + def (key, value) = it.split('=', limit = 2) + env."${key.trim()}" = value.trim() + } + } + withCredentials(projectVcsCredentials) { script { def status = sh returnStatus: true, script: ''' @@ -582,6 +602,13 @@ pipeline { } steps { + script { + params.ENVIRONMENT_VARIABLES.tokenize(',').each { + def (key, value) = it.split('=', limit = 2) + env."${key.trim()}" = value.trim() + } + } + withCredentials(projectVcsCredentials) { script { def status = sh returnStatus: true, script: ''' @@ -642,6 +669,13 @@ pipeline { } steps { + script { + params.ENVIRONMENT_VARIABLES.tokenize(',').each { + def (key, value) = it.split('=', limit = 2) + env."${key.trim()}" = value.trim() + } + } + withCredentials(projectVcsCredentials) { script { def status = sh returnStatus: true, script: ''' @@ -695,6 +729,13 @@ pipeline { } steps { + script { + params.ENVIRONMENT_VARIABLES.tokenize(',').each { + def (key, value) = it.split('=', limit = 2) + env."${key.trim()}" = value.trim() + } + } + sh ''' ORT_OPTIONS="$LOG_LEVEL"