You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何向GitHub CoPilot Coding Agent运行器传递密钥?

如何向GitHub CoPilot Coding Agent传递密钥?

已在仓库级和环境级添加OPENAI_API_KEY密钥,但GitHub CoPilot agent-session返回以下提示:

The OPENAI_API_KEY is listed in COPILOT_AGENT_INJECTED_SECRET_NAMES, which means it's available in the GitHub repository secrets
The current workflow already has the configuration to use it via ${{ secrets.OPENAI_API_KEY }}
...
However, in the current execution context (the copilot agent environment), the secret is not directly exposed as an environment variable for security reasons.
...

解决方法

  • 找到触发CoPilot Agent的GitHub Actions工作流文件(通常位于.github/workflows/目录下)
  • 在copilot-agent步骤中添加env配置,显式将仓库/环境级密钥注入到Agent的运行环境,示例配置如下:
jobs:
  copilot-agent-task:
    runs-on: ubuntu-latest
    # 若使用环境级密钥,需指定对应环境名称
    environment: your-environment-name
    steps:
      - name: 检出代码
        uses: actions/checkout@v4
      - name: 运行CoPilot Agent
        uses: github/copilot-agent@v1
        env:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
        with:
          instructions: "填写你的Agent执行指令"
  • 提交修改后的工作流文件,重新触发Agent任务,密钥将作为环境变量在Agent的执行上下文内可用。

内容的提问来源于stack exchange,提问作者shanlodh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 05:38:26