How do I access GitHub Actions Environment Secrets?
Asked Answered
X

0

6

Pretty simple problem, I am not sure what I am missing.

I have an environment secret:

enter image description here

In this case, the "production" environment is available to all branches. I am simply trying to access the MESSAGE variable in my appsettings replacement action (I have tried adding and removing the repo level MESSAGE to no avail):

- uses: actions/checkout@master
- name: Variable Substitution
  uses: microsoft/variable-substitution@v1
  with:
    files: DummyApi/appsettings.json
  env:
    Message: ${{ secrets.MESSAGE }}

This will replace it with the repo level setting, but not the env level setting, this does not replace it at all:

- uses: actions/checkout@master
- name: Variable Substitution
  uses: microsoft/variable-substitution@v1
  with:
    files: DummyApi/appsettings.json
  env:
    Message: ${{ env.MESSAGE }}

Simply - how do I access the MESSAGE value in an environment? Do I need to set an environment manually or something? Thank you.

ADDED INFO:

What I really want to do is something like this:

on: [push]
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    environment: contains('main', $GITHUB_REF) ? production : development

I know that last line will not work, but it seems if I set the environment, I can see the secrets - I would just like to reuse a lot of the deploy code instead of copy/paste.

Xerophthalmia answered 31/8, 2021 at 21:28 Comment(1)
I've seen examples using outputs to set the job environment value, did you try using this approach? (a first job would set the output based on your contains expression, and the second job would use this output as environment name to perform an operation using a specific env secrets or a repo secrets). I found an example on the video in this article.Janitajanith

© 2022 - 2024 — McMap. All rights reserved.