如何在Azure DevOps中自动版本npm包(不触发新管道)? 我们想做什么

如何在Azure DevOps中自动版本npm包(不触发新管道)? 我们想做什么,npm,azure-devops,semantic-versioning,Npm,Azure Devops,Semantic Versioning,我们正在使用Azure管道(Azure Pipelines.yml)来自动化ci/cd。部分配置完成了发布到Azure工件的项目版本控制。我们还试图将其配置为更新package.json中的现有版本号,而不触发Azure DevOps中的新管道 这是我们的azure pipelines.yml文件的相关部分: - script: | git config --global user.email "email@example.com" git con

我们正在使用Azure管道(
Azure Pipelines.yml
)来自动化ci/cd。部分配置完成了发布到Azure工件的项目版本控制。我们还试图将其配置为更新
package.json
中的现有版本号,而不触发Azure DevOps中的新管道

这是我们的
azure pipelines.yml
文件的相关部分:

  - script: |
      git config --global user.email "email@example.com"
      git config --global user.name "User name"
      npm version patch -m "Bump version to %s [skip ci]" --force
    displayName: 'Bump release version'
  - script: |
      npm pack
    displayName: 'Package package'
这可以很好地将包发布到Azure工件提要,但不会更新
package.json中的现有版本

我们的
package.json
包含以下内容:

"release": {
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        "@semantic-release/changelog",
        [
            "@semantic-release/npm",
            {
                "npmPublish": false
            }
        ],
        [
            "@semantic-release/git",
            {
                "assets": [
                    "dist/",
                    "package.json",
                    "CHANGELOG.md"
                ],
                "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
            }
        ]
    ]
}
问题:
我们如何更新脚本以确保
包.json
中的
版本
值也被更新,而不会触发另一个管道执行(这将导致触发新管道执行的无休止循环)?

您可以添加另一个脚本任务以推回到devops git repo。但首先,您需要添加步骤并将persistCredentials设置为true,以验证git命令。请参见以下示例:

- checkout: self
  persistCredentials: true

- script: |

   git config --global user.email "email@example.com"
   git config --global user.name "User name"
   npm version patch -m "Bump version to %s [skip ci]" --force

  displayName: 'Bump release version'

- script: |

   git push origin HEAD:$(Build.SourceBranchName)

  displayName: 'Update Git Repo'
  

因为您在提交消息中有[skip ci]。推回更新的package.json文件不会触发新的构建。请参阅。

谢谢!这很有效。如果有人遇到
GenericContribute
错误,请参阅。如果仍然无法使其工作,请复制错误中的uid
Build/
部分,并将其粘贴到“安全”选项卡上的“用户”字段中,如其他问题中的答案所示,并根据答案所述设置适当的权限。