以下步骤如何访问GitHub部署环境

问题描述 投票:0回答:1

在 GitHub 中的作业中,我们可以定义环境,我们可以通过以下步骤访问它吗?我能得到的最接近的结果显示在下面的代码片段中。但如果这些信息在

github
上下文中可用,那就太好了。

# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
  workflow_dispatch:
    #inputs:
    #  target-env:
    #    type: environment
    #    default: dev
  
jobs:
  test:
    runs-on: ubuntu-latest
    environment: ${{ vars.ENVIRONMENT_DEV }}
    
    steps:
      - name: GitHub Context
        run: echo "${GITHUB_CONTEXT}"
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
      - name: Job Context
        run: echo "${JOB_CONTEXT}"
        env:
          JOB_CONTEXT: ${{ toJson(job) }}
      - name: Steps Context
        run: echo "${STEPS_CONTEXT}"
        env:
          STEPS_CONTEXT: ${{ toJson(steps) }}
      - name: Runner Context
        run: echo "${RUNNER_CONTEXT}"
        env:
          RUNNER_CONTEXT: ${{ toJson(runner) }}
      - name: Strategy Context
        run: echo "${STRATEGY_CONTEXT}"
        env:
          STRATEGY_CONTEXT: ${{ toJson(strategy) }}
      - name: Matrix Context
        run: echo "${MATRIX_CONTEXT}"
        env:
          MATRIX_CONTEXT: ${{ toJson(matrix) }}
      - name: Print Environment
        run: echo ${{ vars.ENVIRONMENT_DEV }}
github github-actions
1个回答
0
投票

我认为你应该直接引用环境变量或使用 env 关键字来设置和访问它们。

  test:
    runs-on: ubuntu-latest
    environment: 
      name: ${{ secrets.ENVIRONMENT_DEV }}
© www.soinside.com 2019 - 2024. All rights reserved.