Skip to content

Commit c041f3d

Browse files
committed
support setting pipeline env vars from the config
This allows one to specify: ``` env: VAR: value ``` In the config. The VAR=value will then be set in the pod created by k8s/OpenShift AND in any multi-arch builder remote sessions. IOW the env var/value should be available anywhere a COSA command will be run. Since this solution is more generic we'll drop the use_osbuild pipeline knob here too in favor of `env: COSA_USE_OSBUILD: true`.
1 parent df80b28 commit c041f3d

6 files changed

+44
-14
lines changed

docs/config.yaml

+8-2
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,20 @@ streams:
9999
skip_cloud_uploads: true
100100
# OPTIONAL: dont perform Brew uploads
101101
skip_brew_upload: true
102-
# Use newly added support for building images using OSBuild
103-
use_osbuild: true
102+
# Set the COSA_USE_OSBUILD environment variable to force use of OSBuild
103+
# for image building.
104+
env:
105+
COSA_USE_OSBUILD: true
104106
# OPTIONAL: require kernel + kernel-rt versions to match
105107
check_kernel_rt_mismatch_rhcos: true
106108

107109
# REQUIRED: architectures to build for other than x86_64
108110
additional_arches: [aarch64, ppc64le, s390x]
109111

112+
# OPTIONAL: environment variables to set inside the COSA container
113+
env:
114+
VAR: value
115+
110116
# OPTIONAL: S3 bucket and key to which to upload build artifacts. For reference,
111117
# the builds.json file will be located at
112118
# `${s3.bucket}/${s3.builds_key}/builds/builds.json`.

jobs/build-arch.Jenkinsfile

+5-3
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def stream_info = pipecfg.streams[params.STREAM]
7676

7777
def cosa_controller_img = stream_info.cosa_controller_img_hack ?: cosa_img
7878

79-
// Determine if we should use osbuild for image building
80-
def use_osbuild = pipeutils.get_use_osbuild_for_stream(pipecfg, params.STREAM)
79+
// Grab any environment variables we should set
80+
def container_env = pipeutils.get_env_vars_for_stream(pipecfg, params.STREAM)
8181

8282
// If we are a mechanical stream then we can pin packages but we
8383
// don't maintain complete lockfiles so we can't build in strict mode.
@@ -113,6 +113,7 @@ lock(resource: "build-${params.STREAM}-${basearch}") {
113113
cosaPod(cpu: "${ncpus}",
114114
memory: "${cosa_memory_request_mb}Mi",
115115
image: cosa_controller_img,
116+
env: container_env,
116117
serviceAccount: "jenkins") {
117118
timeout(time: timeout_mins, unit: 'MINUTES') {
118119
try {
@@ -142,6 +143,7 @@ lock(resource: "build-${params.STREAM}-${basearch}") {
142143
// performs garbage collection on the remote if we fail to clean up.
143144
pipeutils.withPodmanRemoteArchBuilder(arch: basearch) {
144145
def session = pipeutils.createCosaRemoteSession(
146+
env: container_env,
145147
expiration: "${timeout_mins}m",
146148
image: cosa_img,
147149
workdir: WORKSPACE,
@@ -287,7 +289,7 @@ lock(resource: "build-${params.STREAM}-${basearch}") {
287289

288290
// Build QEMU image
289291
stage("Build QEMU") {
290-
shwrap("cosa shell -- env COSA_USE_OSBUILD=${use_osbuild} cosa buildextend-qemu")
292+
shwrap("cosa buildextend-qemu")
291293
}
292294

293295
// This is a temporary hack to help debug https://github.com/coreos/fedora-coreos-tracker/issues/1108.

jobs/build.Jenkinsfile

+4-3
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ if (params.ADDITIONAL_ARCHES != "none") {
8383

8484
def stream_info = pipecfg.streams[params.STREAM]
8585

86-
// Determine if we should use osbuild for image building
87-
def use_osbuild = pipeutils.get_use_osbuild_for_stream(pipecfg, params.STREAM)
86+
// Grab any environment variables we should set
87+
def container_env = pipeutils.get_env_vars_for_stream(pipecfg, params.STREAM)
8888

8989
// If we are a mechanical stream then we can pin packages but we
9090
// don't maintain complete lockfiles so we can't build in strict mode.
@@ -153,6 +153,7 @@ lock(resource: "build-${params.STREAM}") {
153153
cosaPod(cpu: "${ncpus}",
154154
memory: "${cosa_memory_request_mb}Mi",
155155
image: cosa_img,
156+
env: container_env,
156157
serviceAccount: "jenkins") {
157158
timeout(time: timeout_mins, unit: 'MINUTES') {
158159
try {
@@ -352,7 +353,7 @@ lock(resource: "build-${params.STREAM}") {
352353

353354
// Build QEMU image
354355
stage("Build QEMU") {
355-
shwrap("cosa shell -- env COSA_USE_OSBUILD=${use_osbuild} cosa buildextend-qemu")
356+
shwrap("cosa buildextend-qemu")
356357
}
357358

358359
// This is a temporary hack to help debug https://github.com/coreos/fedora-coreos-tracker/issues/1108.

jobs/bump-lockfile.Jenkinsfile

+4-3
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def s3_stream_dir = pipeutils.get_s3_streams_dir(pipecfg, params.STREAM)
4545

4646
def stream_info = pipecfg.streams[params.STREAM]
4747

48-
// Determine if we should use osbuild for image building
49-
def use_osbuild = pipeutils.get_use_osbuild_for_stream(pipecfg, params.STREAM)
48+
// Grab any environment variables we should set
49+
def container_env = pipeutils.get_env_vars_for_stream(pipecfg, params.STREAM)
5050

5151
def getLockfileInfo(lockfile) {
5252
def pkgChecksum, pkgTimestamp
@@ -67,7 +67,7 @@ def ncpus = ((cosa_memory_request_mb - 512) / 1536) as Integer
6767
def timeout_mins = 240
6868

6969
lock(resource: "bump-lockfile") {
70-
cosaPod(image: cosa_img,
70+
cosaPod(image: cosa_img, env: container_env,
7171
cpu: "${ncpus}", memory: "${cosa_memory_request_mb}Mi",
7272
serviceAccount: "jenkins") {
7373
timeout(time: timeout_mins, unit: 'MINUTES') {
@@ -111,6 +111,7 @@ lock(resource: "bump-lockfile") {
111111
if (arch != "x86_64") {
112112
pipeutils.withPodmanRemoteArchBuilder(arch: arch) {
113113
archinfo[arch]['session'] = pipeutils.createCosaRemoteSession(
114+
env: container_env,
114115
expiration: "${timeout_mins}m",
115116
image: cosa_img,
116117
workdir: WORKSPACE,

jobs/debug-pod.Jenkinsfile

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ cosa_img = cosa_img ?: pipeutils.get_cosa_img(pipecfg, params.STREAM)
4242

4343
def stream_info = pipecfg.streams[params.STREAM]
4444

45+
// Grab any environment variables we should set
46+
def container_env = pipeutils.get_env_vars_for_stream(pipecfg, params.STREAM)
47+
4548
// We'll just always use latest for the controller image here.
4649
def cosa_controller_img = "quay.io/coreos-assembler/coreos-assembler:main"
4750

@@ -57,6 +60,7 @@ podName += UUID.randomUUID().toString().substring(0, 8)
5760
cosaPod(cpu: "${ncpus}",
5861
memory: "${cosa_memory_request_mb}Mi",
5962
image: cosa_controller_img,
63+
env: container_env,
6064
serviceAccount: "jenkins",
6165
name : podName) {
6266
timeout(time: params.TIMEOUT as Integer, unit: 'HOURS') {
@@ -73,6 +77,7 @@ cosaPod(cpu: "${ncpus}",
7377
// performs garbage collection on the remote if we fail to clean up.
7478
pipeutils.withPodmanRemoteArchBuilder(arch: params.ARCH) {
7579
def session = pipeutils.createCosaRemoteSession(
80+
env: container_env,
7681
expiration: "${params.TIMEOUT}h",
7782
image: cosa_img,
7883
workdir: WORKSPACE,

utils.groovy

+18-3
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,18 @@ def get_source_config_ref_for_stream(pipecfg, stream) {
123123
}
124124
}
125125

126-
def get_use_osbuild_for_stream(pipecfg, stream) {
127-
return pipecfg.streams[stream].use_osbuild ? '1' : ''
126+
def get_env_vars_for_stream(pipecfg, stream) {
127+
def x = [:]
128+
// Grab the globally configured env vars first
129+
if (pipecfg.env) {
130+
x.putAll(pipecfg.env)
131+
}
132+
// Values in stream specific env vars override
133+
// the global ones.
134+
if (pipecfg.streams[stream].env) {
135+
x.putAll(pipecfg.streams[stream].env)
136+
}
137+
return x
128138
}
129139

130140
// Parse and handle the result of Kola
@@ -221,6 +231,7 @@ def bump_builds_json(stream, buildid, arch, s3_stream_dir, acl) {
221231
// build on a different architecture.
222232
//
223233
// Available parameters:
234+
// env: (optional) map of key/val pairs of environment variables to set
224235
// expiration: string that represents a golang duration for how
225236
// long the container should last (i.e. 4h, 30m)
226237
// image: string that represents the container image to pull
@@ -229,9 +240,13 @@ def createCosaRemoteSession(params = [:]) {
229240
def expiration = params['expiration']
230241
def image = params['image']
231242
def workdir = params['workdir']
243+
def envArgs = []
244+
if (params['env']) {
245+
envArgs = params['env'].collect { k, v -> "--env ${k}=${v}" }
246+
}
232247
def session = shwrapCapture("""
233248
cosa remote-session create --image ${image} \
234-
--expiration ${expiration} --workdir ${workdir}
249+
${envArgs.join(" ")} --expiration ${expiration} --workdir ${workdir}
235250
""")
236251
return session
237252
}

0 commit comments

Comments
 (0)