首页 > 解决方案 > 如何仅在活动 LTS 甚至当前版本上运行 azure 管道?

问题描述

我目前在我的azure-pipelines.yml

trigger:
- master

pool:
  vmImage: ubuntu-latest
strategy:
  matrix:
    node_14_x:
      node_version: 14.x
    node_16_x:
      node_version: 16.x

steps:
- task: NodeTool@0
  inputs:
    versionSpec: $(node_version)
  displayName: 'Install Node.js'

其中 v14.x 的 Node 是在撰写本文时活动的 LTS,而 v16.x 是在撰写本文时 Node 的当前(偶数)版本。

我想重构它,所以我不必手动更新版本,所以我正在寻找这样的东西(注意:下面不起作用):

trigger:
- master

pool:
  vmImage: ubuntu-latest
strategy:
  matrix:
    node_active_LTS:
      node_version: LTS_VERSION
    node_current:
      node_version: CURRENT_EVEN

steps:
- task: NodeTool@0
  inputs:
    versionSpec: $(node_version)
  displayName: 'Install Node.js'

我一直提到even,这是因为 Node.js 奇怪的版本(例如 15.x)不打算支持很长时间。在这里阅读更多

先感谢您!

标签: node.jsazureyamlazure-pipelines

解决方案


同意布鲁诺的观点。

Azure DevOps Pipeline 中没有自动执行此操作的现成方法。

有两个限制:

  1. Azure Pipeline 中没有与 nodejs 版本相关的预定义变量。您不能直接在 node_version 字段中使用变量值(例如 LTS_VERSION 和 CURRENT_EVEN )。

  2. strategy字段中,不支持运行脚本或其他命令获取 node.js 的版本。

因此,没有任何开箱即用的方法可以在 Azure Devops 中自动实现 node.js 版本来代替手动设置。


推荐阅读