GitHub Actions Certification — Question 8
Which of the following commands will set the $FOO environment variable within a script, so that it may be used in subsequent workflow job steps?
Answer options
- A. run: echo "::set-env name=FOO::bar"
- B. run: echo "FOO=bar" >> $GITHUB_ENV
- C. run: echo ${{ $FOO=bar }}
- D. run: export FOO=bar
Correct answer: B
Explanation
The correct answer is B because it appends the variable definition to the $GITHUB_ENV file, which is the proper method to set environment variables in GitHub Actions. Option A is outdated and no longer recommended, option C contains incorrect syntax, and option D sets the variable only for the current shell session, not for subsequent steps.