Expand environment variables in yaml

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      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

            Assignee:
            Unassigned
            Reporter:
            Matt Buckland
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: