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

Azure Pipelines特定虚拟机Download Artifacts任务JavaScript执行报错

Azure DevOps流水线特定虚拟机下载构件报错解决方案

问题背景

我在Azure DevOps Pipelines中搭建了一套部署到虚拟机环境的流水线,这套流水线在大部分虚拟机上都能正常运行,但在某一台特定虚拟机上,执行下载构件的JavaScript代码时触发报错。即使移除了实际部署步骤,错误依然存在。

流水线YAML代码

displayName: Deploy Test Environment
jobs:
  - deployment: deploy_test
    displayName: Deploy Test
    condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/Test'))
    environment: 
      name: msptst
      resourceType: virtualMachine
    strategy:
      runOnce:
        deploy:
          steps:
            - template: templates\azure-test-deployment-template.yml

部署步骤模板代码

- task: ExtractFiles@1
  inputs:
    archiveFilePatterns: '$(PIPELINE.WORKSPACE)/**/*.zip'
    destinationFolder: '$(PIPELINE.WORKSPACE)/ExtractedArtifact'
    cleanDestinationFolder: false
    overwriteExistingFiles: true
- script: DIR "$(PIPELINE.WORKSPACE)" /S
  continueOnError: true

报错信息

C:\PROGRA~2\DYNATR~1\oneagent\agent\bin\125121~1.202\any\nodejs\nodejsagent.js:2611
  const e = Buffer.allocUnsafe(8), d = 2 ** 32;
                                          ^

SyntaxError: Unexpected token *
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at module.js:676:12
    at Array.forEach (native)
##[error]Exit code 1 returned from process: file name 'E:\azagent\A1\externals\node\bin\node.exe', arguments "E:\azagent\A1\_work\_tasks\DownloadBuildArtifacts_a433f589-fce1-4460-9ee6-44a624aeb1fb\0.178.0\main.js".
Finishing: Download Artifact

问题根源

报错中的SyntaxError: Unexpected token *指向2 ** 32这个幂运算符——该语法属于ES2016标准,仅Node.js 6.4.0及以上版本支持。这台特定虚拟机存在两个可能的问题:

  1. 本地安装的Node.js版本过低,无法识别该语法;
  2. 虚拟机上的Dynatrace OneAgent劫持了Node.js执行环境,流水线实际使用的是OneAgent自带的旧版本Node.js,而非Azure DevOps Agent自带的兼容版本。

解决步骤

  • 检查并升级Node.js版本:登录虚拟机,执行node -v查看版本,若低于6.4.0则升级到最新LTS版本;
  • 排除Dynatrace干扰:临时禁用OneAgent后重新运行流水线,确认是否恢复正常。若为OneAgent问题,将其更新至最新版本;
  • 显式指定Agent自带Node.js:在部署模板开头添加NodeTool任务,强制使用兼容版本:
    - task: NodeTool@0
      inputs:
        versionSpec: '16.x'
      displayName: 'Install compatible Node.js'
    
  • 更新Azure DevOps Agent:将该虚拟机上的Agent升级到最新稳定版,确保其自带的Node.js版本满足任务要求。

内容的提问来源于stack exchange,提问作者Ryan Richard Klopka

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 03:35:29