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

如何将Node脚本输出存入Azure任务变量?脚本执行异常求助

问题:Azure Pipeline中无法将Node.js脚本输出存入任务变量

我尝试将Node.js脚本的输出存储到Azure Pipeline任务变量中,编写了如下YAML管道:

resources:
  repositories:
    - repository: "testRepo"
      type: git
      name: project/repo

trigger: none

stages:
  - stage: Test
    variables:
      Test_Result: ''
    jobs:
    - job: TestJob
      displayName: Test
      steps:

      - checkout: self
      - checkout: testRepo

      - script: |
          npm install
        workingDirectory: $(System.DefaultWorkingDirectory)\testrepo

      # Not working - script not running
      - script: |
          echo "##vso[task.setvariable variable=Test_Result]$(node test.js)"
        workingDirectory: $(System.DefaultWorkingDirectory)\testrepo

但运行该YAML时,上述标注“Not working - script not running”的脚本步骤未执行;而直接单独运行如下脚本步骤时,node test.js可正常执行并显示输出:

- script: |
     node test.js
  workingDirectory: $(System.DefaultWorkingDirectory)\tp-ui-caseMgmtV8

相关输出截图:

  • 含变量赋值的脚本步骤输出:含变量赋值的脚本步骤输出
  • 单独运行node test.js的输出:单独运行node test.js的输出

不清楚问题出在哪里,恳请指点解决方向,谢谢。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 03:16:04