jenkins - 如何在詹金斯中自动增加 XML elt 值
问题描述
我的项目 repo 中有一个 xml 文件,在结帐后,我想为每个构建自动增加版本号的最后一个值。我已经在使用 xmlslurper 访问版本号并将其存储在一个变量中。我的管道脚本中有类似的内容,而我的 xml 文件只是一个带有 1.0.0.0 的单行脚本,我希望为每个构建自动增加最后一个数字。注意:我不想使用詹金斯的内部版本号。只需在我的项目存储库中将最后一位更改为 $BUILD_NUMBER 就很容易了。
@NonCPS
String getVersion(String path)
{
def version = new xmlSlurper().parse(new File(path))
return version.toString()
}
node
{
stage ('checkout') {
.........
}
stage ('build) {
def pwd2=pwd()
def v=getVersion("${pwd2}/VersionNumber.xml")
sh ' dotnet publish path/to/project -p:Fileversion=$v '
}
}
解决方案
没有插件,所以我想你可以使用 groovy。如果你不喜欢版本号,试试这个
def test = "1.1.1.1"
def splitted = test.split('\\.')
splitted[3] = (((splitted[3] as BigDecimal) + 1) as String)
def testInc = splitted.join('.')
print(testInc)
对于内部版本号方法,我建议将整个版本保留在 jenkinsfile 中,应该很简单:
def version = "1.0.0.${env.BUILD_NUMBER}"
推荐阅读
- google-cloud-firestore - 文档更新 - 没有更改的更新仍然需要 1 次写入吗?
- maven - E: 找不到包 openjdk-11-jdk
- git - VS 2019 Git 超时连接到 bitbucket
- sql-server - Select可以阻止插入的表格吗?
- r - 更改基本 R 图中的字体
- javascript - Three.js:将矩阵应用于对象组,然后更新它们的位置
- python - facebook 先知对少于 25 次观察的时间序列进行持续预测
- spring - 使用 keycloak 进行 Springboot 测试
- python - 如何在使用 Dialogflow API 时减少延迟?
- node.js - 如何在 gRPC 服务器中限制 IP 访问?