如何在 Build 命令中传递 Jenkins BUILD_TIMESTAMP 变量来创建报告?
Posted
技术标签:
【中文标题】如何在 Build 命令中传递 Jenkins BUILD_TIMESTAMP 变量来创建报告?【英文标题】:How can I pass the Jenkins BUILD_TIMESTAMP variable in the Build command to create reports? 【发布时间】:2021-08-07 10:49:48 【问题描述】:我在 Jenkins 中有以下构建命令-
C:\Users\<username>\AppData\Roaming\npm\newman run C:\\Users\\<username>\\Documents\\<Project_Name>\\API_TestCases_collection\\LandlordSales_B2L_L2Q.postman_collection.json -r htmlextra --reporter-htmlextra-export C:\Users\waniijag\Documents\<Project_Name>\NewmanReports\report.html
问题是每个新版本的报告都会重叠。我想通过在 Timestamp_report.html
之前附加时间戳来使用它另外,我在 Jenkins 中启用了环境变量,如下所示:
如何在上述命令中传递时间戳?
提前致谢!
【问题讨论】:
你read the docs了吗? $BUILD_TIMESTAMP ? 嗨@IanW,是的。但我不知道我应该如何使用它们。我尝试在我的命令中传递“$Build_Timestamp”和 $Build_Timestamp。示例:C:\Users\waniijag\Documents<Project_Name>\NewmanReports\$BUILD_TIMESTAMP_report.html
但是,它不起作用。我还需要在系统环境中设置该变量吗?
先安装插件plugins.jenkins.io/build-timestamp,然后按照@Michael的指导尝试
plugins.jenkins.io/build-timestamp 已安装。
您能不能只使用\report_$(date "+%d%m%Y_%H%M").html
之类的东西或等效的窗口来为报告添加时间戳?
【参考方案1】:
下面的sn-p应该打印出时间戳:
echo "$BUILD_TIMESTAMP"
或包含在您的路径中:
echo "C:\Users\waniijag\Documents<Project_Name>\NewmanReports\$BUILD_TIMESTAMP_report.html"
重要提示:您必须使用"
而不是'
。
请参阅Groovy string interpolation 文档了解更多信息。
【讨论】:
当我在路径中使用 $BUILD_TIMESTAMP 时,它会通过在 report.html 中附加 $BUILD_TIMESTAMP 而不是附加 BUILD_TIMESTAMP 值来生成报告。以上是关于如何在 Build 命令中传递 Jenkins BUILD_TIMESTAMP 变量来创建报告?的主要内容,如果未能解决你的问题,请参考以下文章
Jenkins Docker安装及利用Docker-build-step插件部署Docker