为什么该动作无法访问机密? [英] Why The Action Cannot Access Secrets?

查看:61
本文介绍了为什么该动作无法访问机密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个工作流,以使用Github Actions将Nuget软件包部署到Github软件包存储库中.

I am trying to create a workflow to deploy Nuget packages to Github Package Repository using Github Actions.

在这种情况下,

  • 存储库位于组织内部
  • 我是该组织的所有者
  • 我对存储库具有管理员访问权限
  • 存储库中列出了机密
  • 提交是我的
  • 该提交是对分支的直接提交

但是该操作无法访问机密

But the action CANNOT access the secrets

下面是我要执行的工作流程

Below is the workflow I am trying to execute

name: Build and Publish
on:
push:
  branches:
    - gh-packages
jobs:
build_and_publish:
env:
  ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Publish Packages to NuGet
runs-on: ubuntu-latest
steps:
  - uses: actions/checkout@v2
  - uses: actions/setup-dotnet@v1
    with:
      dotnet-version: "3.0.100"
  - name: Dump Github Context
    env:
      CONTEXT: ${{ toJson(github) }}
      SECRETS: ${{ toJson(secrets) }}
      TOK: ${{ secrets.ACCESS_TOKEN }}
      TEST: ${{ secrets.TEST }
    run: |
      echo $ACCESS_TOKEN
      echo $TOK
      echo $TEST
      echo $GITHUB_TOKEN
      echo "$SECRETS"
      echo "$CONTEXT"
  - name: Setup Config
    run: sed "s/ACCESS_TOKEN/$ACCESS_TOKEN/g" .nuget.config > nuget.config
  - run: cat nuget.config
  - name: Build
    run: dotnet build -c Release
  - name: Publish
    run: chmod +x ./push.sh && ./push.sh

GITHUB_TOKEN和自定义机密(例如ACCESS_TOKEN)均不起作用.

Both GITHUB_TOKEN and custom secrets like ACCESS_TOKEN are not working.

添加01:

即使将环境变量名称设置为GITHUB_TOKEN也无法正常工作

Even when setting the environment variable name as GITHUB_TOKEN doesn't seam to be working

name: Build and Publish
env:
   GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
...

推荐答案

发生此问题是由于对我的误解,我认为如果秘密值正确传递给操作,则秘密值应显示在日志中.

This problem occurred because of a misunderstanding of mine, which I thought the secret values should show up in the logs if they are passed to the action correctly.

我将 Ben Winding 秘密值在操作日志中被清除.不要期望在操作日志中看到实际值.获取清理后的文本意味着该值已传递给操作.您可以在脚本中使用该值,但无法在日志中看到它们.检查 Ben的答案以了解如何看到这些值,但不建议这样做.

Secret values are scrubbed in action logs. Don't expect to see the actual values in the action logs. Getting the scrubbed text means the value has been passed to the action. you can use the value within the script but you cant see them in the logs. Check Ben's Answer for How you can see the values, but it is not recommended.

这篇关于为什么该动作无法访问机密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆