Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment variables in github actions

I want to pass maven image version as as env variable but when i am trying to access that env.MAVEN_VERSION variable getting error

Error- The workflow is not valid. .github/workflows/Merge.yaml (Line: 13 image:) Unrecognized named-value: 'env'. Located at position 1 within expression: env.MAVEN_VERSION

Yaml File ---

on:
  push:
    branches: [ master ]

env:
  MAVEN_VERSION: maven:3.8.6-jdk-11
  
jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: ${{ env.MAVEN_VERSION }}
    steps:
    - name: Env Variable
      run: echo ${{ env.MAVEN_VERSION }}
like image 776
Mayur Kadam Avatar asked Sep 13 '25 21:09

Mayur Kadam


1 Answers

While env is not available, outputs from previous jobs are. Consider the following example

on:
  push:
    branches: [ master ]

env:
  MAVEN_VERSION: maven:3.8.6-jdk-11
  
jobs:
  prepare-image:
    runs-on: ubuntu-latest
    steps:
       - run: echo "null"
    outputs:
      image: ${{ env.MAVEN_VERSION }}

  build:
    runs-on: ubuntu-latest
    needs: [prepare-image]
    container:
      image: ${{ needs.prepare-image.outputs.image }}
    steps:
    - name: Echo output
      run: echo ${{ needs.prepare-image.outputs.image }}
like image 85
riemann Avatar answered Sep 15 '25 13:09

riemann