-
Type:
New Feature
-
Resolution: Unresolved
-
Priority:
Minor
-
Component/s: kubernetes-plugin
-
None
-
Environment:jenkins/jenkins:lts
k8s plugin 1.12.4
Hi,
I'm trying to access and environment variable when using a yaml pod definition but I only get null values. This is what I'm using:
yaml """
apiVersion: v1
kind: Pod
metadata:
annotations:
iam.amazonaws.com/role: arn:aws:iam::${TARGET_ACCOUNT_ID}:role/jenkins-admin-mgmt
spec:
containers:
- name: docker
image: ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/docker:${DOCKER_IMAGE_TAG}
command: ["sleep"]
args: ["86400"]
"""
ACCOUNT_ID, REGION and DOCKER_IMAGE_TAG are all set on the jenkins master pod as env vars. TARGET_ACCOUNT_ID is a job parameter and expands just fine.
Elsewhere, these variables are available, like so:
agent {
kubernetes {
label "${JOB_NAME}"
inheritFrom 'default'
containerTemplate {
name 'jnlp'
image '${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/jenkins/jnlp-slave:${AGENT_IMAGE_TAG}'
That works, even though it's in single quotes ^^, but in yaml it doesn't.
I've tried all sorts of combinations of escaping and setting variables with environment blocks, trying to set variables outside the pipeline etc, but I can't make it work. Maybe I'm doing something wrong, or maybe it's broken. Maybe it's not supposed to work?
Any advice greatly appreciated.
Thanks,
Matt
- is related to
-
JENKINS-53094 Option to expand variables in yamlFile
-
- Open
-
-
JENKINS-57930 Pipeline script from SCM does not expand build parameters/env variables for declarative pipeline with yamlFile specified
-
- Resolved
-