jenkins - 从当前工作空间中创建的 xml 文件中读取 jenkinsfile 中的数据
问题描述
前段时间,我尝试连接 jenkins 和 gerrit,并将 jenkins 的 cppcheck 输出作为注释发送到 gerrit:
- 我为 jenkins 和 gerrit 安装了适当的补丁(没关系,它可以工作)
- 在 jekinsfile 我试图运行 cppckeck 并将其输出保存到 xml 文件(它的作品)
问题就在这里,当我试图读取 xml 文件时,我有信息表明没有这样的文件。我看到该脚本有不同的根目录(我很好地打印了目录)。我认为我的实验 jenkinsfile 的代码解释了问题:
pipeline {
agent any
stages {
stage('Example') {
steps {
gerritReview labels: [Verified: 0]
sh 'pwd'
sh 'cppcheck --enable=all --inconclusive --xml --xml-version=2 *.c* 2> cppcheck.xml'
script {
def parser = new XmlParser()
def doc = parser.parse("cppcheck.xml"); // No xml file here because script {}
// is run in different place
}
}
}
post {
always {
gerritReview score: 1
step([$class: 'CppcheckPublisher', pattern: 'cppcheck.xml', ignoreBlankFiles: false, treshold: "0"])
}
} }
如何加载此文件。或者我做错了?(我的意思是把 gerrit 与 jenkins 集成,目的是运行 cppcheck 和 cpplint 并在 gerrit 中显示结果)。
解决方案
如果文件在您的仓库中,您需要先查看仓库 https://www.jenkins.io/doc/pipeline/steps/workflow-scm-step/
pipeline {
agent any
stages {
stage('Example') {
steps {
checkout scm // ADD THIS LINE
gerritReview labels: [Verified: 0]
sh 'pwd'
sh 'cppcheck --enable=all --inconclusive --xml --xml-version=2 *.c* 2> cppcheck.xml'
script {
def parser = new XmlParser()
def doc = parser.parse("cppcheck.xml");
}
}
}
post {
always {
gerritReview score: 1
step([$class: 'CppcheckPublisher', pattern: 'cppcheck.xml', ignoreBlankFiles: false, treshold: "0"])
}
}
}
推荐阅读
- python - 使用 Numba 和 Cuda 规范化 3 个向量的数组
- python - 如何在字典列表中找到特定键的唯一值?
- ruby-on-rails - 如何将数据库列设置为 Rails 夹具中的空字符串?
- python - 具有相应真实掩码的操纵图像
- html - Navbar Dropdown 扩展 Nav 而不是悬停在
- python - 如何更改按钮内文本的大小?
- excel - 陷入无限循环
- python - Tensorflow 2子类模型回溯错误
- swift - 尝试从 Firebase 字段值中设置几个变量...异步函数问题
- python - 查找关于 Python 包的 Kwargs 和其他信息