Skip to content

Commit

Permalink
feat(jenkins): Allow to set arbitrary environment variables
Browse files Browse the repository at this point in the history
This is useful when referring to environment variables in a `config.yml`
template, like API keys.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Nov 29, 2023
1 parent f563d2a commit 738790c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions integrations/jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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: '''
Expand Down Expand Up @@ -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: '''
Expand Down Expand Up @@ -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: '''
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 738790c

Please sign in to comment.