Azure DevOps 管道中的 npm 版本 [英] npm version in Azure DevOps pipeline
问题描述
我在 Azure DevOps 中有一个构建管道,它通过 npm pack
发布工件,以便稍后发布到 Artifacts Feed.
我想通过 GIT 设置我的主要和次要版本,但补丁版本与内部版本号相关联.例如
1.2.20201212.4
其中 1 和 2 是通过 GIT 手动更新的major.minor 版本和 20201212.4 是补丁和修订号
- 添加替换令牌任务.
注意:根据我的测试,npm 包在 azure devops 中不支持 xx.x.x.x 版本格式(npm 发布).它可以支持x.x.x-x.
所以你可以这样设置buildnumber:$(Date:yyyyMMdd)-$(Rev:r)
.
结果:
更新:
您可以尝试使用 Npm Version 命令.
npm 版本 0.0.$(build.buildnumber) --no-git-tag-version
更新 2:
您可以尝试使用以下 powershell 脚本获取 Package.json 中的版本字段.然后更新补丁号.
$filePath = "$(Build.sourcesdirectory)\package.json";#文件路径$Jsonfile= 获取内容 $filePath |ConvertFrom-Json$version = $Jsonfile.version回声 $version$major,$minor,$build = $version.Split('.')$build = "$(build.buildnumber)";$bumpedVersion = $major,$minor,$build -join(".")回声 $bumpedVersion写主机##vso[task.setvariable variable=version]$bumpedVersion";
在 Npm 版本中,您可以运行以下命令:
version $(version) --no-git-tag-version
I have a build pipeline in Azure DevOps which releases artifact via npm pack
for later publishing into Artifacts Feed.
I would like to set my major and minor version via GIT but patch version to tie with build number. E.g.
1.2.20201212.4
where 1 and 2 is major.minor version manually updated via GIT and 20201212.4 is a patch and revision number set by build pipeline
Could someone help me to figure out the required npm version
command parameters to preserve minor.major version from source code and update only patch and revision part from $(Build.BuildNumber) variable?
In Azure Devops, you could use the Replace Tokens task from the Replace Tokens Extension.
Then you could add the task before the NPM pack task to replace the variable in Package.json -> Version field.
Here are the steps:
Package.Json file:
{
"name": "helloword",
"version": "0.0.#{SetNumber}#",
"description": "Hello World",
"main": "server.js",
...
}
Build Pipeline:
- Set Variables in Build Pipeline.
- Add the Replace Tokens task.
Note: Based on my test, npm package cannot support xx.x.x.x version format(npm publish) in azure devops. It can support the x.x.x-x.
So you can set buildnumber like this:$(Date:yyyyMMdd)-$(Rev:r)
.
Result:
Update:
You could try to use the Npm Version command.
npm version 0.0.$(build.buildnumber) --no-git-tag-version
Update2:
You could try to use the following powershell script to get the version field in the Package.json. Then update the patch number.
$filePath = "$(Build.sourcesdirectory)\package.json" #filepath
$Jsonfile= Get-Content $filePath | ConvertFrom-Json
$version = $Jsonfile.version
echo $version
$major,$minor,$build = $version.Split('.')
$build = "$(build.buildnumber)"
$bumpedVersion = $major,$minor,$build -join(".")
echo $bumpedVersion
Write-Host "##vso[task.setvariable variable=version]$bumpedVersion"
In Npm version, you could run the following command:
version $(version) --no-git-tag-version
这篇关于Azure DevOps 管道中的 npm 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!