【问题标题】:Run node shebang script from an Azure Pipeline step从 Azure Pipeline 步骤运行节点 shebang 脚本
【发布时间】:2019-11-13 00:35:24
【问题描述】:

是否可以从 Azure Pipeline 步骤调用节点 shebang 脚本?

我有一个沿这些线的节点shebang,但我不知道从管道步骤调用它涉及什么:

const processUrl = async (url, reportDir) => {
  console.log(chalk.yellow(`about to run lighthouse tests against ${url}`));
  try {
    await runCmd('docker',
    [
      'run',
      '--rm',
      '-it',
      '-v',
      `${reportDir}:/home/chrome/reports`,
      '-v',
      `${path.join(process.cwd(), 'lighthouse')}:/home/chrome/reports/config`,
      'femtopixel/google-lighthouse',
      url.replace("localhost", "host.docker.internal"),
      '--config-path',
      './config/lighthouse-config.js',
      '--output',
      'html',
      '--output',
      'json'
    ])
  } catch(err) {
    console.error(err);
  }
}

【问题讨论】:

    标签: node.js azure azure-devops azure-pipelines


    【解决方案1】:

    需要在文件顶部添加shebang字符序列:

    #!/usr/bin/env node
    

    现在添加一个 Bash 任务并使用 node 命令运行该文件。

    如果要确保安装了 Node,可以使用任务Node.js tool installer 任务:

    - task: NodeTool@0
      inputs:
        versionSpec: 8.x
    

    例如文件test.js是:

    #!/usr/bin/env node
    const [,, ...args] = process.argv
    console.log(`Hi ${args}`)
    

    我的 Bash 脚本是:

    - bash: 'node test.js shayki'
    

    结果是:

    【讨论】:

    • 抱歉,我的问题可能不清楚。我想知道是否会安装节点,或者我能否保证节点安装在与运行管道步骤的进程相同的虚拟机上
    • 哦好的,在Microsoft Hosted agent Node已经安装好了,如果你使用你的agent你可以使用Node安装任务,看我的更新。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-17
    • 1970-01-01
    • 2013-05-06
    • 1970-01-01
    • 2021-10-26
    • 2021-06-04
    相关资源
    最近更新 更多