简体   繁体   中英

Is there a way to pass secrets under a different key in main.workflow in Github Actions?

My Github Action requires "GITHUB_TOKEN" from secrets but I want to be able to declare my own key and pass it in.

This is only an issue in .github/main.workflow . Inside .github/workflows/my-workflow.yml you can declare environment variables yourself:

jobs:
  my-job:
    ...
    env:
      TOKEN_KEY_THEY_WANT: ${{ secrets.HOW_I_NAMED_IT }}

and below is how they expect main.workflow to be configured:

action "My Job" {
  uses = "my_repo/action_folder@branch-name"
  secrets = ["GITHUB_TOKEN"]
}

and this is how I want to be able to do:

action "My Job" {
  uses = "my_repo/action_folder@branch-name"
  env = {GITHUB_TOKEN = "$MY_CUSTOM_TOKEN"}
  secrets = ["MY_CUSTOM_TOKEN"]
}

The Github Actions docu doesn't seem to cover this topic and most of its content is based around their workflow.yml format. I don't know if this is a simple syntax error but if anybody has any idea on what to do, I'd very much appreciate it.

According to https://help.github.com/en/articles/about-github-actions#migrating-github-actions-from-hcl-to-yaml-syntax ,

Support for the HCL syntax in GitHub Actions will be deprecated on September 30, 2019.

If you participated in the limited public beta and created workflows with the HCL syntax GitHub Actions, you will need to upgrade to the new limited public beta that uses YAML syntax. When your repository is eligible to upgrade, you'll see an invitation in your repository. You must accept the invitation before you can use the new limited public beta.

Any workflows that you created with the HCL syntax will need to be updated to the new YAML syntax. To automatically convert your workflows and actions, see " Migrating GitHub Actions from HCL syntax to YAML syntax ."

So you'll need to convert your main.workflow file to a YAML syntax file under .github/workflows . You can name it anything you like, but I'd probably call it main.yml if I were you. This will allow you to use other secrets besides GITHUB_TOKEN , and since you have to do it anyway before the end of the month, you might as well get started on the conversion process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM