1

How does one go about updating a variable that is declared in github action workflow?

Consider the following:


name: Test Variable

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
env:
  DAY_OF_WEEK: Monday

jobs:
  job1:
    name: Job1
    runs-on: ubuntu-latest
    env:
      Greeting: Hello
    steps:
      - name: "Say Hello John it's Monday"
        run: |
          echo $Greeting=Holla
          echo "$Greeting $First_Name. Today is $DAY_OF_WEEK!"
        env:
          First_Name: John
      
      - name: "Eval"
        run: echo $Greeting $First_Name

So here I'm attempting to update Greeting then eval it later but GH is throwing

Invalid workflow file.You have an error in your yaml syntax on line 21.

So, if I were to update Greeting First_Name and DAY_OF_WEEKhow would I go about doing that?

Update

Fixed yaml syntax but the variable is not updated. Output for Eval is

Run echo $Greeting $First_Name
  echo $Greeting $First_Name
  shell: /usr/bin/bash -e {0}
  env:
    DAY_OF_WEEK: Monday
    Greeting: Hello
Hello
2
  • Indention is part of yaml syntax. The on block should not be indented out like that Commented Apr 7, 2022 at 15:12
  • Thats just SO text entry. Thats not the issue here. I'll try and update. Commented Apr 7, 2022 at 15:40

1 Answer 1

2

Assign a variable:

run echo "Greeting=HOLLA" >> $GITHUB_ENV

using the variable

run echo "$Greeting"

docs: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable

(Also make sure yours yml-file's indentation is correct.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.