In the below workflow github actions when I'm able to print and get the value of environment variable XML_PATH
in a different JOB but the same variable XML_PATH
errors as unrecognized when used in a different JOB having reusable
workflow.
How is the job(PRINT_VARS)
having reusable workflow
any different from a job(READ_VARS_FROM_XML)
that runs-on
when accessing variables like XML_PATH
---
name: CICD_RECYCLE
env:
storeserver: "remotehost"
REPO_NAME: ${{ github.event.repository.name }}
ENVIRONMENT: ${{ inputs.ENVIRONMENT }}
XML_PATH: "\\\\$env:storeserver\\D$\\Jenkins\\$env:REPO_NAME\\$env:ENVIRONMENT"
on:
push:
branches:
- "develop"
workflow_dispatch:
inputs:
ENVIRONMENT:
type: choice
options:
- qa
- dev
- test
- prod
jobs:
SETVARS:
runs-on: 'mywindowsrunner'
outputs:
# outputxmlpath: $env:XML_PATH
myvar: ${{ inputs.ENVIRONMENT }}
steps:
- name: Set environment variable for XML_PATH
run: |
echo "XML_PATH=$env:XML_PATH">> $env:GITHUB_ENV
PRINT_VARS:
needs:
- SETVARS
runs-on: 'mywindowsrunner'
steps:
- name: Powershell to export variables to ENVIRONMENT
run: |
echo "XML PATH: ${{ env.XML_PATH }}"
READ_VARS_FROM_XML:
needs:
- SETVARS
uses: mybank/betech/.github/workflows/extractfromxml.yml@mm365
with:
xml_Path: "${{ env.XML_PATH }}\\web.Parameters.xml"
# xml_Path: '${{ needs.SETVARS.outputs.outputxmlpath }}'
secrets: inherit
Output for PRINT_VARS
:
XML PATH: \remotehost\D$\Jenkins\betech\qa
Error for READ_VARS_FROM_XML
:
Invalid workflow file: .github/workflows/main_recycle.yml#L85
The workflow is not valid. .github/workflows/main_recycle.yml (Line: 68, Col: 17): Unrecognized named-value: 'env'. Located at position 1 within expression: env.XML_PATH
As you can see in the output ${{ env.XML_PATH }}
prints the values fine in job PRINT_VARS
whereas it errors when used in job READ_VARS_FROM_XML
.
We can get the variable using outputs
but I wanted to use env
variables.
Kindly suggest.
The solution is to pass the environment variables as the output of a job, like here