gpt4 book ai didi

jenkins kubernetes-plugin 存档/junit

转载 作者:行者123 更新时间:2023-12-03 17:35:14 25 4
gpt4 key购买 nike

我有一个多容器作业,它通过 kubernetes-jenkins 插件在 k8s 上运行。一切正常,但我无法 junitarchiveArtifacts任何事物。我怀疑是因为它只存在于容器中但不确定。代码如下:

def label = "foo-${UUID.randomUUID().toString()}"

podTemplate(
label: label,
containers: [
containerTemplate(name: 'c1', image: 'c1'),
containerTemplate(name: 'c2', image: 'c2'),
containerTemplate(name: 'c3', image: 'c3'),
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
],
) {
node(label) {
stage('test') {
container('c1') {
sh """
cd /some-path
./generate-junit-xml
"""

archiveArtifacts allowEmptyArchive: true, artifacts: '/some-path/foo.xml'

sh "cat /some-path/foo.xml"
}
}
}
}

def label = "foo-${UUID.randomUUID().toString()}"

podTemplate(
label: label,
namespace: 'jenkins',
imagePullSecrets: [ 'myreg' ],
containers: [
containerTemplate(name: 'c1', image: 'c1'),
containerTemplate(name: 'c2', image: 'c2'),
containerTemplate(name: 'c3', image: 'c3'),
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
],
) {
node(label) {
stage('test') {
container('c1') {
sh """
./something-that-generates-junit-foo-xml
"""

archiveArtifacts allowEmptyArchive: true, artifacts: '/abs/path/to/foo.xml'

sh "cat /abs/path/to/foo.xml"
}
}
}
}

构建日志显示以下输出:
[Pipeline] archiveArtifacts
Archiving artifacts
WARN: No artifacts found that match the file pattern "/some-path/foo.xml". Configuration error?
[Pipeline] sh
[test-pipeline] Running shell script
+ cat /some-path/unittest.xml
<?xml version="1.0" encoding="utf-8"?>...</xml>

感谢您的帮助!

最佳答案

两者 junitarchiveArtifacts只能存档 WORKSPACE 内的文件,除非您明确这样做,否则容器不会与主机(jenkins WORKSPACE 所在的位置)一起刮削任何卷

我用以下方法解决了这个问题:
- 在我保存文件的地方添加额外的卷

hostPathVolume(hostPath: '/tmp', mountPath: '/tmp')

- 从 tmp 复制文件到工作区 File Operations Plugin
dir("/tmp/screenshots") {
fileOperations([fileCopyOperation(excludes: '', flattenFiles: true, includes: '*.png', targetLocation: "${WORKSPACE}/screenshots")])
}

- 存档工件
archiveArtifacts allowEmptyArchive: true, artifacts: 'screenshots/**/*.png'

关于jenkins kubernetes-plugin 存档/junit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48938704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com