Skip to content

azure-pipelines-task-lib unnecessarily injects diagnostics into output streams #1100

Open
@reillysiemens

Description

@reillysiemens

When attempting to use tl.execAsync to read the contents from a command's stdout I have encountered an issue where diagnostic information containing the command name and arguments are injected into the output stream.

This JavaScript below serves as a minimal reproduction of the issue.

const assert = require("node:assert");
const fs = require("node:fs");
const { readFile, writeFile } = require("node:fs/promises");
const tl = require("azure-pipelines-task-lib/task");

(async () => {
  // Write "Hello World!" to foo.txt.
  const fooContents = "Hello, World!";
  await writeFile("foo.txt", fooContents);

  // Create an optional write stream to bar.txt.
  const stream = fs.createWriteStream("bar.txt");
  const options = { outStream: stream };
  await tl.execAsync("cat", ["foo.txt"], options);

  // Read back the contents of bar.txt.
  const barContents = await readFile("bar.txt", "utf-8");

  // 💣💥 Boom! They aren't equal! bar.txt is prefixed with:
  // [command]/usr/bin/cat foo.txt
  assert.strictEqual(
    fooContents,
    barContents,
    `foo.txt: "${fooContents}" != bar.txt: "${barContents}"`,
  );
})();

I don't know whether there are contexts where it would make sense to have this output in the stream coming from the subprocess, so I'm not sure if this is intentional, but it seems like bug to me. I think that the following code is responsible for the issue.
 

if (!optionsNonNull.silent) {
optionsNonNull.outStream!.write(this._getCommandString(optionsNonNull) + os.EOL);
}

Unfortunately, if you try to suppress this output by setting silent: true in the options then the entire output is supressed, which is not desirable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions