【问题标题】:Azure Pipelines build task test fail with error: "Must initialize"Azure Pipelines 构建任务测试失败并出现错误:“必须初始化”
【发布时间】:2019-07-09 14:42:02
【问题描述】:

当我直接使用 node 调用 index.js 时,它可以工作,但是当我运行 mocha 测试时,任务失败并显示“必须初始化”错误消息。

我的任务 index.ts 如下所示:

import * as path from "path";
import tl = require('azure-pipelines-task-lib/task');
import trm = require('azure-pipelines-task-lib/toolrunner');
import os = require('os');

async function run() {
    try {
        const libmanJson = tl.getPathInput('libmanjson', true, true); //this throws
    }
    catch (err) {
        console.log(err.message);
        tl.setResult(tl.TaskResult.Failed, err.message);
    }
}

mocha tests 从这里复制:docs.microsoft.com: Add a build or release task

【问题讨论】:

    标签: node.js typescript azure-devops mocha.js azure-pipelines-build-task


    【解决方案1】:

    遇到同样的问题,通过向 TaskMockRunner 提供答案解决

    let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
        "which": {
            "echo": "/mocked/tools/echo"
        },
        "exec": {
            "/mocked/tools/echo Hello, from task!": {
                "code": 0,
                "stdout": "atool output here",
                "stderr": "atool with this stderr output"            
            }
        }
    };
    tmr.setAnswers(a)
    

    【讨论】:

      猜你喜欢
      • 2020-02-23
      • 2019-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-25
      • 2015-04-19
      • 1970-01-01
      相关资源
      最近更新 更多