gpt4 book ai didi

github-actions - with和env和有什么不一样

转载 作者:行者123 更新时间:2023-12-03 13:37:35 26 4
gpt4 key购买 nike

我是github action的新手,我看到用于配置步骤的两件事(如果我错了,请纠正我)withenv
两者之间的区别是什么以及如何使用它们。

uses: someAction
with:
x: 10
y: 20
env:
x1: 30
y2: 40

最佳答案

with-专门用于将参数传递给操作
env-专门用于引入可以根据资源范围进行访问的环境变量

  workflow envs - can be accessed by all resources in the workflow except services

job envs - can be accessed by all resources under job except services

step envs - can be accessed by any resource withing the step
这是有关如何处理参数的示例
假设在 Action yaml中使用以下参数创建了 Action
name: 'Npm Audit Action'
inputs:
dirPath:
description: 'Directory path of the project to audit'
required: true
default: './'
然后,我们将通过工作流程中的with标记提供此参数
- name: Use the action
uses: meroware/npm-audit-action@v1.0.2
with:
dirPath: vulnerable-project
然后在 Action 代码中,如果构建一个节点js Action ,我们将像这样处理它
const core = require("@actions/core");
const dirPath = core.getInput("dirPath");
带有 Action 的Env的访问方式有所不同,假设我们正在构建一个节点js Action ,然后将通过process.env对其进行访问。回到我们的示例 Action
name: 'Npm Audit Action'
env:
SOME_ENV: 'hey I am an env'
然后可以通过以下方式访问
const { someEnv: SOME_ENV } = process.env

关于github-actions - with和env和有什么不一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63663436/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com