GithubAction 分割字符串变量值或如何使用 NodeJS 输出

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

我正在尝试制作一个 Github 工作流程。

我的操作是使用节点脚本来更新文件,我在其他步骤中需要新版本。

我试图获取我的脚本的价值

  - name: Update File
    id: update_file
    run: echo $(npm run patch-file)

回声正在给予

> patch-file > node patch-file.ts file patch 0.0.16

文件和补丁是我的脚本的参数。

脚本中的这一行输出了 0.0.16 值

console.log(version);

如何在 Github 操作中检索值 0.0.16 以便在后续步骤中使用?

node.js github-actions
1个回答
0
投票

我认为你可以将自定义变量设置为

$GITHUB_ENV
,如下所示:

- name: Set and Retrieve Github ENV variables
    shell: bash
    run: |
       # Define
       testVar='testVarValue'
       # Set
       echo "testVar=$testVar" >> "$GITHUB_ENV"

testVar
变量将在下一个 CI 步骤中通过
$GITHUB_ENV
变得可用

© www.soinside.com 2019 - 2024. All rights reserved.