Ashar
Ashar

Reputation: 3065

how to interpolate workflow level variable into another workflow level variable github actions

I'm new to github actions.

Below is my workflow:

name: Example

on: [push, workflow_dispatch]

env:
  APPNAME: 'myapp1'
  APPURL: "https://mybank/$APPNAME/widgets/hello.json" 

jobs:
  test:
    runs-on: windows-latest

    steps:
      - name: Print variables
        run: |
          echo "APPURL is: ${{ env.APPURL }}"

Output:

Run echo "APPURL is: https://mybank/$APPNAME/widgets/hello.json"
APPURL is: https://mybank//widgets/hello.json

I understand that env. cannot be used under at workflow level.

Is it possible to have variable interpolation APPNAME at workflow level i.e for APPURL?

Upvotes: 0

Views: 274

Answers (1)

GuiFalourd
GuiFalourd

Reputation: 23270

This is due to the windows-latest runner using powershell by default to run command lines.

In that case, informing the shell: bash will work.

steps:
  - name: Print variables
    run: |
      echo "APPURL is: ${{ env.APPURL }}"
    shell: bash

# Will print: APPURL is: https://mybank/myapp1/widgets/hello.json

Note that using the ubuntu-latest or macos-latest runners will work as well without informing the shell, as they use bash as default.

I've made an example here using this workflow implementation with another example for concatenation that can be useful depending on what you want to achieve.

Upvotes: 1

Related Questions