azure-pipelines-task-lib: Mock Test Runner fails to download a new NodeJS distribution

Please check our current Issues to see if someone already reported this https://github.com/Microsoft/azure-pipelines-task-lib/issues

Environment

azure-pipelines-task-lib version: 2.9.3

Issue Description

While executing unit tests, when calling MockTestRunner.run() a binary distribution of NodeJS is being downloaded. While running on a ubuntu-latest agent, the download fails without any information error.

Expected behaviour

The NodeJS binary is downloaded successfully. The test runs.

Actual behaviour

An error is thrown during the test with the following message:

      Downloading file: https://nodejs.org/dist/v10.15.1/node-v10.15.1-linux-x64.tar.gz

Steps to reproduce

  1. Clone https://github.com/codexarcana/azure-tasks
  2. Create an azure pipeline with the following code:
        npm install
        npm run test
    

Logs

FAIL tests/integration.test.ts
  ● Console

    console.log
      Downloading file: https://nodejs.org/dist/v10.15.1/node-v10.15.1-linux-x64.tar.gz

      at MockTestRunner.downloadFile (node_modules/azure-pipelines-task-lib/mock-test.js:228:17)

  ● should succeed with simple inputs



       6 | 
       7 |     const testPath = path.join(__dirname, 'success.integration.js');
    >  8 |     const testMockRunner = new MockTestRunner(testPath);
         |                            ^
       9 | 
      10 |     testMockRunner.run(10);
      11 | 

      at doRequest (node_modules/sync-request/index.js:27:11)
      at MockTestRunner.downloadFile (node_modules/azure-pipelines-task-lib/mock-test.js:230:22)
      at MockTestRunner.downloadTarGz (node_modules/azure-pipelines-task-lib/mock-test.js:242:14)
      at MockTestRunner.downloadNode (node_modules/azure-pipelines-task-lib/mock-test.js:206:22)
      at MockTestRunner.getNodePath (node_modules/azure-pipelines-task-lib/mock-test.js:147:25)
      at new MockTestRunner (node_modules/azure-pipelines-task-lib/mock-test.js:28:30)
      at tests/integration.test.ts:8:28
      at step (tests/integration.test.ts:33:23)
      at Object.next (tests/integration.test.ts:14:53)
      at tests/integration.test.ts:8:71

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 15 (4 by maintainers)

Most upvoted comments

I’m facing the same issue as well (using node v12.4.0 and azure-pipelines-task-lib 2.10.0). It seems like the problem is the buffer size to sync-request.

I had to change line 25 in sync-request/index.js to include max buffer size to make it work. var res = spawnSync(process.execPath, [require.resolve('./lib/worker.js')], {input: req, maxBuffer: 50 * 1024 * 1024});

I’m using azure-pipelines-task-lib version: 2.9.5 in Azure DevOps - Node 10

The error mentioned above comes up on Ubuntu 18 as well as Windows…

When will this be fixed?

Hi everyone! The root cause of the problem is a known issue with the outdated version of sync-request (https://github.com/ForbesLindesay/sync-request/issues/81). Updating task-lib version to latest solved the issue in @ElderMael’s repository. If updating task-lib is not an option for you, than the easiest fix would be to modify sync-request’s index.js inside node_modules by adding maxBuffer: 1024 ** 4 to spawnSync options

image

Feel free to reopen this issue if you have any questions.

Finally solved by following below steps to bypass the node.exe downloading

  1. Downloaded node.exe from https://nodejs.org/dist/v10.21.0/win-x64/node.exe and saved it in home folder i.e. “C:\Users<UserName>\azure-pipelines-task-lib_download\node10\node.exe”
  2. Updated “<TaskName>\node_modules\azure-pipelines-task-lib\mock-test.js” and replaced function that trying to download node.exe with the path in step 1. Updated Line: 28 Line updated: this.nodePath = getNodePath() Line updated with: _this.nodePath = ‘C:\Users\azure-pipelines-task-lib\download\node10\node.exe’;
  3. Referred below MS Doc to install latest node and npm packages. Here I installed latest version v14.15.1, however in step1 downloaded v10.21.0 as its hardcoded in azure-pipelines-task-lib. May be azure-pipelines-task-lib is compliant with v10.21.0. https://docs.microsoft.com/en-us/azure/devops/extend/develop/add-build-task

I was able to fix this issue by using Node v10.18.0 as opposed to a newer version