【问题标题】:jenkins kubernetes-plugin archive/junit詹金斯 kubernetes 插件存档/junit
【发布时间】:2018-08-02 23:16:38
【问题描述】:

我有一个通过 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>

非常感谢您的帮助!

【问题讨论】:

  • 我认为您需要在第一个容器中添加所有步骤。

标签: jenkins jenkins-plugins


【解决方案1】:

junitarchiveArtifacts 都只能归档 WORKSPACE 内的文件,容器不会使用主机(jenkins WORKSPACE 所在的位置)刮除任何卷,除非您明确这样做

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

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

- 使用File Operations Plugin 将文件从tmp 复制到WORKSPACE

dir("/tmp/screenshots") {
    fileOperations([fileCopyOperation(excludes: '', flattenFiles: true, includes: '*.png', targetLocation: "${WORKSPACE}/screenshots")])
}

- 归档工件

archiveArtifacts allowEmptyArchive: true, artifacts: 'screenshots/**/*.png'

【讨论】:

    【解决方案2】:

    将工件复制到 Jenkins 工作区将解决它

    age('test') {
            container('c1') {
                sh """
                  ./something-that-generates-junit-foo-xml
                """
                sh 'cp /abs/path/to/foo.xml ${WORKSPACE}/abs/foo.xml'
                archiveArtifacts allowEmptyArchive: true, artifacts: 'abs/foo.xml'
    
                sh "cat /abs/path/to/foo.xml"
            }
    

    如果你需要所有目录内容,你可以复制目录

    sh 'cp -r /abs/path/to/ ${WORKSPACE}/abs/to'
    archiveArtifacts allowEmptyArchive: true, artifacts: 'abs/to/*.xml'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      • 2021-09-03
      • 2017-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多