hudson.FilePath 通过管道脚本生成魅力报告时缺少错误

hudson.FilePath is missing error when generate allure report via pipeline script

我向管道添加了新阶段:

stage('reports') {
    steps {
    script {
            allure([
                    includeProperties: false,
                    jdk: '',
                    properties: [],
                    reportBuildPolicy: 'ALWAYS',
                    results: [[path: 'target/allure-results']]
            ])
        }
    }
}

但作业因错误而失败:

hudson.remoting.ProxyException: org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing
    at org.jenkinsci.plugins.workflow.steps.StepDescriptor.checkContextAvailability(StepDescriptor.java:260)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:262)
Caused: hudson.remoting.ProxyException: org.codehaus.groovy.runtime.InvokerInvocationException: org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing

测试写在 Python 和生成的 xml 报告上,但不是诱惑报告。

你能帮我解决这个错误吗?

据我所知,您使用 declarative pipeline syntax。在这种情况下,您需要定义 agent 部分。来自官方文档:

Defining agent none at the top-level of the Pipeline ensures that an Executor will not be assigned unnecessarily. Using agent none also forces each stage section to contain its own agent section.

所以,我认为您在管道的顶层使用 agent none,这就是为什么您需要在阶段中添加 agent 部分。像这样:

pipeline {
    agent none 
    stages {
        stage('reports') {
            agent { docker 'openjdk:8-jre' }
            steps {
                script {
                    allure([
                        includeProperties: false,
                        jdk: '',
                        properties: [],
                        reportBuildPolicy: 'ALWAYS',
                        results: [[path: 'target/allure-results']]
                    ])
                }
            }
        }
    }
}

scripted pipeline you need to use this syntax (see allure documentation 了解更多详情):

node {
// script body

allure([
         includeProperties: false,
         jdk: '',
         properties: [[key: 'allure.issues.tracker.pattern', value: 'http://tracker.company.com/%s']],
         reportBuildPolicy: 'ALWAYS',
         results: [[path: 'target/allure-results'], [path: 'other_target/allure-results']]
         ])
}