Skip to content

Commit

Permalink
refactor(jenkins): Move getting Docker build arguments to a function
Browse files Browse the repository at this point in the history
This prepares for getting arguments from another source. In order for
the function to access global variables, the `@Field` annotation is
required, also see [1].

[1]: https://stackoverflow.com/a/50573082/1127485

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Feb 13, 2024
1 parent 884a073 commit 959902c
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions integrations/jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@

import com.cloudbees.groovy.cps.NonCPS

import groovy.transform.Field

import java.io.IOException

import org.jenkinsci.plugins.pipeline.modeldefinition.Utils

@Field
final DOCKER_BUILD_ARGS = '--build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy --build-arg ORT_VERSION='

// Disable the entry point to work around https://issues.jenkins-ci.org/browse/JENKINS-51307.
Expand All @@ -34,8 +37,15 @@ final ORT_FAILURE_STATUS_CODE = 2

def projectVcsCredentials = []
def ortConfigVcsCredentials = []

@Field
def ortVersion = 'JENKINS-SNAPSHOT'

@NonCPS
def getDockerBuildArgs() {
return DOCKER_BUILD_ARGS + ortVersion
}

@NonCPS
static sortProjectsByPathDepth(projects) {
return projects.toSorted { it.definition_file_path.count("/") }
Expand Down Expand Up @@ -320,7 +330,7 @@ pipeline {
agent {
dockerfile {
filename 'Dockerfile-legacy'
additionalBuildArgs DOCKER_BUILD_ARGS + ortVersion
additionalBuildArgs getDockerBuildArgs()
args DOCKER_RUN_ARGS
}
}
Expand All @@ -347,7 +357,7 @@ pipeline {
agent {
dockerfile {
filename 'Dockerfile-legacy'
additionalBuildArgs DOCKER_BUILD_ARGS + ortVersion
additionalBuildArgs getDockerBuildArgs()
args DOCKER_RUN_ARGS
}
}
Expand Down Expand Up @@ -386,7 +396,7 @@ pipeline {
agent {
dockerfile {
filename 'Dockerfile-legacy'
additionalBuildArgs DOCKER_BUILD_ARGS + ortVersion
additionalBuildArgs getDockerBuildArgs()
args DOCKER_RUN_ARGS
}
}
Expand Down Expand Up @@ -463,7 +473,7 @@ pipeline {
agent {
dockerfile {
filename 'Dockerfile-legacy'
additionalBuildArgs DOCKER_BUILD_ARGS + ortVersion
additionalBuildArgs getDockerBuildArgs()
args DOCKER_RUN_ARGS
}
}
Expand Down Expand Up @@ -492,7 +502,7 @@ pipeline {
agent {
dockerfile {
filename 'Dockerfile-legacy'
additionalBuildArgs DOCKER_BUILD_ARGS + ortVersion
additionalBuildArgs getDockerBuildArgs()
args DOCKER_RUN_ARGS
}
}
Expand Down Expand Up @@ -589,7 +599,7 @@ pipeline {
agent {
dockerfile {
filename 'Dockerfile-legacy'
additionalBuildArgs DOCKER_BUILD_ARGS + ortVersion
additionalBuildArgs getDockerBuildArgs()
args DOCKER_RUN_ARGS
}
}
Expand Down Expand Up @@ -718,7 +728,7 @@ pipeline {
agent {
dockerfile {
filename 'Dockerfile-legacy'
additionalBuildArgs DOCKER_BUILD_ARGS + ortVersion
additionalBuildArgs getDockerBuildArgs()
args DOCKER_RUN_ARGS
}
}
Expand Down Expand Up @@ -780,7 +790,7 @@ pipeline {
agent {
dockerfile {
filename 'Dockerfile-legacy'
additionalBuildArgs DOCKER_BUILD_ARGS + ortVersion
additionalBuildArgs getDockerBuildArgs()
args DOCKER_RUN_ARGS
}
}
Expand Down Expand Up @@ -850,7 +860,7 @@ pipeline {
agent {
dockerfile {
filename 'Dockerfile-legacy'
additionalBuildArgs DOCKER_BUILD_ARGS + ortVersion
additionalBuildArgs getDockerBuildArgs()
args DOCKER_RUN_ARGS
}
}
Expand Down

0 comments on commit 959902c

Please sign in to comment.